首页 > 解决方案 > Git:如何在没有壁球的情况下修复合并

问题描述

我在没有压缩的情况下合并到 master 现在它显示了对我的分支所做的每一个提交myTestBranch

有什么办法可以修复它以显示单个提交?

标签: gitgithub

解决方案


您可以尝试,rebase但如果存储库被多个开发人员使用,请尝试协调这一点,因为它会更改/更改存储库的历史记录,例如:

$ git rebase -i <commit>

<commit>您想返回/还原的提交的哈希在哪里,在这里,您可以使用它来获取最后一次提交的列表:git log --pretty=oneline --abbrev-commit

当使用选项-i(交互式)变基时,它将打开您的编辑器并显示如下内容:

pick 447dae2 my changes for foo bar
pick 452b764 1
pick 9aaf8b3 2
pick 15a6af0 3
pick f31a830 4
pick dd34521 5

# Rebase 5302aa0..dd34521 onto 5302aa0 (6 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

所以在这里你可以通过为提交添加前缀来“修复”或“挤压”,例如:

pick 447dae2 my changes for foo bar
f 452b764 1
f 9aaf8b3 2
f 15a6af0 3
f f31a830 4
f dd34521 5

# Rebase 5302aa0..dd34521 onto 5302aa0 (6 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit

然后你将不得不推动力量:

$ git push -f

你的梨,可能需要做:

$ git pull --rebase

检查此答案以获取更多详细信息:https ://stackoverflow.com/a/42862404/1135424


推荐阅读