Git advanced commands (2) (git branch operation)

Git branch

1. Display all current branches
Use the git branch command, as shown in the figure:
write picture description here
2. Create a branch
Use git branch to create a new branch name (eq:dev), as shown in the figure:
write picture description here
Description: The content of the new branch created and the branch we created The content of the master at that time is the same
3. Switch branch
Use git checkout branch name (eq:dev), as shown in the figure:
write picture description here
4. Delete branch (cannot delete the current branch)
use git branch -d branch name (eq:dev2 ), as shown in the figure:
write picture description here
5. Modify the name of the current branch
Use git branch -m to create a new branch name (eq:master), as shown in the figure:
write picture description here
Note: there cannot be a branch with the same name
6. Create a branch and change Branch
Use git checkout -b branch name (eq:dev), as shown in the figure:
write picture description here
7. Merge branch (need to submit to the repository before merging)
use git merge branch name (eq:dev), as shown in the figure:
write picture description here

write picture description here
8. Compare the file differences between the workspace and the staging area
Use the git diff command, as shown in the figure:
write picture description here
9. Compare the file differences between the staging area and the repository
Use the git diff –staged command, as shown in the figure:
write picture description here
10. Compare branches Use the git diff
version number version number command, as shown in the figure:
write picture description here
11. Compare the differences of the latest commits of the two branches
Use the git diff branch branch command, as shown in the figure:
write picture description here
Note: The commits here are commits Go to the repository
12. Save the modified content of the workspace to the Git stack
Use the git stash command, as shown in the figure:
write picture description here
Principle: Back up the content of the current workspace, read the relevant content from the latest commit, and let the workspace guarantee It's the same as the last commit, so we can switch branches.
Application scenario: When we modify the content of the workspace on the branch, but we do not want to submit it to the temporary storage area, if we want to switch branches, it is not allowed. At this time, we can use this command, first put Back up our modified content, pull the content of the staging area to the workspace, so that we can switch branches.
13. View all backups in the Git stack
Use the git stash list command, as shown in the figure:
write picture description here
Description: You can use this list to decide where to restore from.
14. Restore our branch according to the backup
Use the git stash apply command, as shown in the figure:
write picture description here
15. Restore the backup according to stash@{}, and delete it after restoring
Use the git stash pop command, as shown in the figure
write picture description here
At this time we only have one backup left 16. Empty the Git stack

Use the git stash clear command, as shown in the figure:
write picture description here
At this time, we found that our backup was gone.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325502322&siteId=291194637