Git合并无历史记录提交

3
我希望在将其他分支合并到主分支时,没有其他分支历史提交。我该怎么做?
我们知道:
git pull --rebase origin test # 表示:只有历史提交没有合并提交。
git pull --no-ff origin test # 表示:历史提交和合并提交。
git pull --ff-only origin test # 表示:只有历史提交没有合并提交。
我想要“仅合并提交”,如何操作?请像这样:

https://github.com/torvalds/linux/commits/master enter image description here

更进一步的问题:

如果我使用"--squash",在合并时将不会自动记录"Merge branch 'xxx' of xxxx"或"Merge tag 'xxx' of xxxx"。需要手动记录吗?

2个回答

2
请注意,您还可以配置合并到的分支自动压缩要合并的提交(如此讨论中所述):
git config branch.<name>.mergeoptions --squash 

git config有以下功能:

branch.<name>.mergeoptions

设置合并到分支<name>的默认选项。
语法和支持的选项与git-merge相同,但当前不支持包含空格字符的选项值。
这样,您就不必为git merge添加任何额外选项了。
如在“在git中,merge --squash和rebase有什么区别?”中提到的那样,这不会记录合并:
这将记录一个合并:
git config branch.<name>.mergeoptions --no-ff

看到“进一步的问题”,你能给我一些建议吗? - kangear
1
@kangear在你的情况下,no-ff会更适合:我已经给出了答案。 - VonC

1
我得到了答案:
   --squash, --no-squash
       Produce the working tree and index state as if a real merge happened
       (except for the merge information), but do not actually make a commit or
       move the HEAD, nor record $GIT_DIR/MERGE_HEAD to cause the next git commit
       command to create a merge commit. This allows you to create a single commit
       on top of the current branch whose effect is the same as merging another
       branch (or more in case of an octopus).

git pull --squash origin test

没问题!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接