Output the patch of a certain range, such as the patch of commit1~commit3, excluding commit1 patch
$ git format-patch <commit1>..<commit3>
output all patches of a file
## such as: mm/slub.c
$ i=0; for line in `git log --reverse --pretty=format:"%h" mm/slub.c`; do i=$[$i+1]; git format-patch -1 --start-number $i $line -o patches/; done
see if the patch is applicable to the current working tree and/or the index file and detects errors. Turns off apply.
let's some commit of other branch to current branch
$ git cherry-pick <commit>
get files of some commit of other branch
$ git checkout <commit> <file name>
When you develop a feature, commit multiple changes through git commit. If you want to merge this change into a single commit, you may do so through git rebase
$ git log
commit 20b6f52f5d70a07117f6d11b2902d72f69ff1ae5 (HEAD -> test)
add: 1
commit f845618b13247321e7b3fcd27fd94d0392dbe6f9
3
commit 373f063d4f68a1cdec3b6b29676d4203a86b4387
2
commit b2dba726e7606b9f5374218c236c4e2d5efb7877
Init
# 1. Select the range that you want to merge, b2dba72~20b6f52(exception b2dba72)
$ git rebase -i b2dba72 20b6f52
or
$ git rebase -i b2dba72
or
$ git rebase -i HEAD~3
pick 373f063 2
pick f845618 3
pick 20b6f52 add: 1
## 2. Modify the above information, rearrange, and merge commit, such as rearranging 20B6f52 after 373f063 and squash to 373f063
pick 373f063 2
squash 20b6f52 add: 1
pick f845618 3
## 3. Then save and exit, change the commit information, and save the exit.
$ git log
commit 4612f3b2bf08ef705b2b70dc8f2e1d8f14023a9b (HEAD)
3
commit c02e774166119ff4830b5a2f4db48b97b74dd290
2
test: add: 1
commit b2dba726e7606b9f5374218c236c4e2d5efb7877
Init
The remote repository has new commits, but the local repository also has new commits. How to synchronize the new commits of the remote repository to the local repository?
$ git rebase <branch>
When we need to actively merge new feature branches
$ git merge <branch>
Displays the commit of each line of a file
$ git blame <file>
or
$ tig blame <file>
当我们想要知道 commit A 是在哪一个新merge feature合入时,
如何找到对应的merge commit ?