"Pro Git" Chapter 3 Branch

  • 1. Introduction to branches
    • What git saves is not file differences, but file snapshots at different times
    • Objects in the git repository:

      • commit object: all commit information containing a pointer to the previous commit
      • Tree object: record the directory structure and blob object index
      • blob object: save file snapshot
    • HEAD pointer: point to the current local branch, which can be considered as an alias of the current branch
      • git log --oneline --decorate Use --decorate to view the commit object currently pointed to by each branch
      • git log --oneline --decorate --graph --all, it will output your commit history, the direction of each branch and the branch forking of the project. 
  • 2. New branch creation and merging
    • Common commands
      • git branch [branch-name]: Create a new branch, but don’t switch
      • git chekcout [branch-name]: switch to the branch, the HEAD pointer will point to the specified branch
      • git checkout -b [branch-name]: Create a new branch and switch branches, which is equivalent to the sum of the above commands
      • git branch -d [branch-name]: delete branch
    • Branch merge
    • Conflict resolution
  • 3. Branch management (end)
    • git branch: display all branches, * is the branch pointed to by the current HEAD
    • git branch -v: display all branches, and display the last commit of each branch (v refers to verbose)
    • View the branches that have been merged or not merged into the current branch
      • git branch --merged: Check which branches have been merged into the current branch
        • Usually the branch without * in front of the branch in the list can be deleted with git branch -d, because it has been integrated into another branch, so nothing will be lost

      • git branch --no-merged: Check which branches have not been merged into the current branch
        • Because these branches contain work that has not been merged, they will fail when deleted (in the current branch) using git branch -d
        • Forcibly delete git branch -D [branch-name]
  • 4. Branch development workflow (end)
    • Long-term branch: only keep completely stable code on the master branch
  • 5. Remote branch (end)
    • Fundamental
      • Remote warehouse: master branch in remote warehouse
      • Local warehouse:
        • master is the local branch, used to save the progress of the local master branch
        • origin/master is the local tracking branch, used to track the remote master branch
        • Note: The local origin/master may not be the same as the remote master, you need to use git pull to synchronize
    • Display remote branch information
      • git ls-remote: Get a complete list of remote references
      • git remote show: display remote branch information
    • Push
      • git push origin local-name:remote-name
      • Example: git push origin aaa:bbb pushes the local aaa branch to the bbb branch of the origin warehouse
    • Pull
      • git pull
    • Delete remote branch
      • git push origin --delete remote-name
  • 6. Rebase (git rebase temporarily ignored)

Guess you like

Origin blog.csdn.net/hanhan122655904/article/details/114639366