一、分支、合并
1、合并一个特定提交 a specific commit
git cherry-pick commit-id 把commit-id代表的本次提交合并到当前分支,如果有冲突需要解决后,提交
2、fast-forward 和 non-fast-forward
比如有master分支,最新提交commit-id-1,现在基于master分支新建develop分支,在develop分支开发提交commit-id-2,那么现在把develop合并(git merge)到master分支,则只需要移动master的ref到commit-id-2,不会生成一个新的commit-id,然后删除develop分支,那么现在的git log --graph里面根本不会看到develop分支。如果使用git merge --no-ff develop,则会生成一个新的提交commit-id,在删除develop分支后,git log --graph可以看到develop分支以及分支合并情况。这两种方式各有利弊:1)方式1使得log简洁,2)方式2可以重现合并记录,体现开发过程。
The --no-ff
flag prevents git merge
from executing a "fast-forward" if it detects that your current HEAD
is an ancestor of the commit you're trying to merge. A fast-forward is when, instead of constructing a merge commit, git just moves your branch pointer to point at the incoming commit. This commonly occurs when doing a git pull
without any local changes.
However, occasionally you want to prevent this behavior from happening, typically because you want to maintain a specific branch topology (e.g. you're merging in a topic branch and you want to ensure it looks that way when reading history). In order to do that, you can pass the --no-ff
flag and git merge
will always construct a merge instead of fast-forwarding.
Similarly, if you want to execute a git pull
or use git merge
in order to explicitly fast-forward, and you want to bail out if it can't fast-forward, then you can use the --ff-only
flag. This way you can regularly do something like git pull --ff-only
without thinking, and then if it errors out you can go back and decide if you want to merge or rebase.
参考:
https://backlog.com/git-tutorial/cn/stepup/stepup7_4.html