1. What matters at work are three commands

(1) git commit

(2) git cherry-pick

(3) git stash

2, Git commit changes the content of a commit comment

Work requirements, every submission code needs to have a card ID, if you forget to add the card ID, it will not be pushed, so it will involve the modification of the latest submission record, or the modification of a previous submission record

1. Submit the code and add comments
Git commit -mCopy the code
2. Modify the content of the last annotation, that is, the last submitted annotation
Git commit --amend 1, enter I, go to edit page 2, modify comment 3, press Esc, shift + : 4, enter wq, and press Enter to exitCopy the code
3. Find that there is something wrong with the annotation written in a previous submission and modify the content of the annotation written in a previous submission

The second, third, or even earlier submission of comment content

1, git rebase -i HEAD~3 (1) Change the pick to edit: this means that, (2) Change "pick" to "drop:" which means that the comment will be deleted. At this point: I change the third: "pick" to "edit" and type esc, shift + : ", wq, exit save 3 and follow the prompts to git commit --amend  git rebase --continue 5, git push origin xxxxCopy the code
4, reset directly to a commit
Git reset --hard paste commitId 4, git push -f origin XXXX //Copy the code

Git cherry-pick perfect commit specification

For some teams, Git merge is a command that the project leader does not use because it brings up a lot of spam messages. Fortunately for me, if you want to move code from one branch to another and you know exactly what’s new, you can just use cherry-pick

1. Copy a commit to the current branch
git checkout master
git cherry-pick xxxxxxxx
Copy the code

It can also not be a hash if it’s a branch name

Git cherry-pick branch21.08.04 git cherry-pick branch21.08.04Copy the code
2. Duplicate multiple commits
Git cherry-pick <hashA> <hashB> <hashC> Git cherry-pick <hashA> <hashE> # include hashA git cherry-pick <hashA>^.. <hashB>Copy the code
3, cherry-pick merge code conflicts

If the code conflicts, git cherry-pick will stop for a while and resolve the conflict. Once the conflict is resolved, continue cherry-pick

git add .
​
git cherry-pick --continue
Copy the code

If your code conflicts and you don’t want to merge, go back to where you were before the operation

git cherry-pick --abort
Copy the code

4. Git Stash temporary local code

When you are developing on Dev, there is a bug in the project and you need to fix it urgently, but your project is just finished and you don’t want to commit it yet. In this case, you can use git Stash command to save the changes to the stack, and then smoothly switch to the Hotfix branch to fix it. Switch to the dev branch again to recover the inner flexibility you just saved from the stack

Because of an oversight, something that should have been developed on Dev was developed on Master, so you need to switch to Dev again. You can use git Stash to save the content to the stack. When you switch back to dev branch, restore the content again

1. Temporary local code
Git Stash SaveCopy the code

Result of executing the preceding command

stash@{0}: On zlm: 0227
stash@{1}: WIP on master: 14b03d3 update
Copy the code
2. See how much cached code there is locally
 git stash list
Copy the code
3. Pop up the contents of the current Stash and apply it to the working directory corresponding to the current branch to clear the contents temporarily existing in the stack
git stash pop 
Copy the code
4, move the contents of the stack to the current directory, unlike git stash pop, this command does not remove contents from the stack, can be used for multiple branches, there is no removal in the stack
git stash apply stash@{0} 
Copy the code
Remove the specified stash from the stack
git stash drop stash@{0}  
Copy the code
6. Clear the local stack
 git stash clear
Copy the code
7. Check the difference between the specified Stash and the current directory
git stash show stash@{0}
Copy the code
Create a branch from the latest Stash
Git stash branch21.08.04Copy the code