git rebase -i : I only want the last commit

标签 git

我一直在一个分支上工作:

       C1--D1--E1 branch
      /
 A--B--C--D--E--F master

在一个小型测试仓库中使用“git rebase -i master”的分支,我可以到达这里:

 A--B--C--D--E--F--E1 master

问题是,当存在 merge 冲突时,git 要我从分支中逐一解决每个提交。我一直在进行大量的试验和错误,因此,我有很多提交 - 我只想将工作树 merge 到 master 上,而不需要每次提交。

如果我进行正常 merge ,我会得到所有的提交。

你会怎么做?

最佳答案

为了只获得一次提交,这就是你要做的:

目前,您的分支有 3 个不同的提交。因此,将其移动到不同的分支: 假设您的分支名为 testBranch

git branch newBranch
git reset --hard HEAD~3 (Or as many commits as you have)
git cherry-pick newBranch

有关更多信息,请参阅此答案:Git - only push up the most recent commit to github

如果您现在在“testBranch”上执行 git log,您会发现您只有最后一次提交 (E1)。您可以使用您想要的任何命令简单地将它与 master merge 。我希望这会有所帮助。

关于git rebase -i : I only want the last commit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22486518/

相关文章:

r - Git 推送失败 (Github/RStudio)

git - 谁动了我的 git assume-unchanged 位?

git - 什么可能导致 `git pull` 无法看到远程更改?

git - 在 Visual Studio 2013 中使用本地 Git 和(远程)TFS

当前和头部之间的 Git 差异

git - 用于 ssh 的 git/stash 上的公钥身份验证不起作用

git - 如何更新镜像的 git 存储库

git - 如何在 "Unable to create ' .git/index.lock' : File exists. 之后恢复 rebase “?

git - 如何在 TeamCity 中使用动态参数?

混帐 : How to merge the changes from a closed pull request?