Common commands for Git branch management

Branch management

command effect
git branch View current branch
git checkout/git switch branch name Switch branch
git merge branch name Merge the specified branch into the current branch
git branch -d branch name Delete specified branch
git diff branch name 1 branch name 2 Show the difference between two branches
git diff branch name 1 branch name 2 file Show the difference of the specified file between two branches
git stash Temporary packaging

git stash

Git stash temporary package (snapshot) usage scenario: the current branch has not been developed and needs to be switched to another branch. Your local changes to the following files will be overwritten by checkout ,please commit your changes or stash them before you switch branches. Your local changes to the following files will be overwritten by checkout, please commit or stash them before switching branches.
Solution: After the other branch operations are completed, switching to the original branch needs to take out the things just saved in the stash: git stash apply stash{number}, it will restore the code before switching the branch. After that, you can delete the things temporarily stored in stash, of course, you can also delete the stash records: git stash pop (delete the top) and git stash clear (delete all)

gitmerge 与 git rebase

go merge go rabase
merge Rebase
The idea visualization page will show the merge of branches The idea visualization page has only one line

Insert picture description hereNote: It is not recommended to use rebase on the public branch of multi-person cooperation. Assume that the B branch is merged to A. Although the commit record of the B branch is earlier than that of the A branch, assuming that the last commit of the A branch is at 9 o'clock in the morning, the B branch The three commit records are at 8 o'clock in the morning, 7 o'clock, and 6 o'clock in the morning. When you merge with B to A, these three commit records will become the time when you merged 9:01, and will run to the top of the A branch.

git merge --squash

Merge the B branch to A. The B branch has too many commit records. If you merge directly, all the commit records will be directly merged into the A branch, which affects the observability of the A branch. git merge --squash will all commit all the commits of the B branch The records are merged into one and submitted to branch A.

cherry-pick

Merge branch B to A. Branch B has too many commit records. If you don't want to become one or submit all commit records, you can use cherry-pick to select a few commits. In the idea visualization tool, there will be a cherry-like icon, that is cherry-pick, hold down shift to select a few commit records and click on the cherry icon to execute.

Guess you like

Origin blog.csdn.net/qq1350975694/article/details/108005783