2023/10/19

git,commit,branch ,cherry-pick ,merge

  • commit 
    • is snapshot of all files
    • not a change set
  •  to store the hash ID of the latest commit in a branch name.
    • branch name is just the lastest hash of commi branch name is just the lastest hash of commit
    • In fact, this is the very definition of a branch name: a name like master simply stores the hash ID of the commit we want to call the latest for that branch. So given the A--B--C string of commits, we just add the name master, pointing to commit C:

  • To remember which branch we want Git to update, as well as which commit we have checked-out right now, Git has the special name HEAD
    • current branch
    • A--B--C--D <-- develop (HEAD), master
    • HEAD still names the current commit.
    • detached HEAD just means that Git has made the name HEAD point directly to some commit instead of attaching it to a branch name

  • git merge
    • git checkout master
      • set HEAD to master
    • git merge develop
      • go backwards from master and develop, to find a shared base commit (祖先), called merge base
      • The merge base commit is determined entirely by the commit graph,
      • git diff baseCommint master  => get change set 1 
      • git diff basecommit  develop   => get change set 2
      • git combine the difference , use  a new commit id to save the result  ( merge commit )
  • cherry-pick
    • git diff somecommitId to get the change set
    • just put the change on current commit(branch)
    • but it maybe not works very well, git use cherry-pick-style merge, force the merge base commit to be the parent of the cherry-picked commit.
    • cherry-pick create a new commit to save the result. 
    •        G--H--F'   <-- master (HEAD)
            /
      ...--D
            \
             E--F   <-- develop
    •  cherry-pick uses Git's merge machinery to do the change-combining, but leaves the graph unmerged, simply making a copy of some existing commit
  • git merge somecommitid(branch)
  • git merge -no-ff

2023/10/12