如何将整个存储库压缩到第一次提交?
我可以将base转换为第一次提交,但这将留给我2次提交。 有没有办法在第一个提交之前引用这个提交?
如何将整个存储库压缩到第一次提交?
我可以将base转换为第一次提交,但这将留给我2次提交。 有没有办法在第一个提交之前引用这个提交?
当前回答
这对我来说效果最好。
git rebase -X ours -i master
这将使git更喜欢你的特性分支;避免艰苦的合并编辑。您的分支需要与主机同步。
ours
This resolves any number of heads, but the resulting tree of the merge is always that of the current
branch head, effectively ignoring all changes from all other branches. It is meant to be used to
supersede old development history of side branches. Note that this is different from the -Xours
option to the recursive merge strategy.
其他回答
这对我来说效果最好。
git rebase -X ours -i master
这将使git更喜欢你的特性分支;避免艰苦的合并编辑。您的分支需要与主机同步。
ours
This resolves any number of heads, but the resulting tree of the merge is always that of the current
branch head, effectively ignoring all changes from all other branches. It is meant to be used to
supersede old development history of side branches. Note that this is different from the -Xours
option to the recursive merge strategy.
我读过一些关于移植的东西,但从来没有深入研究过。
不管怎样,你可以手动压缩最后2次提交,就像这样:
git reset HEAD~1
git add -A
git commit --amend
一行6个字:
git checkout --orphan new_root_branch && git commit
我用HEAD^{tree}尝试了不同的命令,但从zsh得到了这个错误:
zsh: no matches found: HEAD^{tree}
这是ohmyzsh处理扩展的方式,查看这个问题了解更多细节: https://github.com/ohmyzsh/ohmyzsh/issues/449
最简单的解决方法是运行这个命令:
unsetopt nomatch
用嫁接压扁
添加一个文件。git/info/grafts,把你想要成为根的提交散列放在那里
Git日志现在将从该提交开始
要让它“真实”运行git filter-branch