我如何将最后的N承诺集成到一个承诺中?


当前回答

我如何将我的最后一个X承诺集成到一个使用Git的承诺?

git rebase -i HEAD~X

下列内容将显示:

pick 1bffc15c My earlier commit
pick 474bf0c2 My recent commit

# ...

对于你想要的承诺,请用 fixup 取代 pick,所以它会变成:

pick 1bffc15c My earlier commit
fixup 474bf0c2 My recent commit

# ...

如果它在 vim 中打开(终端内默认界面),然后按 Esc 在键盘上,输入 :wq 并输入以保存文件。

查看: 查看 git log

其他回答

使用 git rebase -i <after-this-commit> 并在第二次和随后的命令中取代“squash”或“fixup”,如手册中所描述。

在此例子中, <after-this-commit> 是 SHA1 hash 或当前分支的 HEAD 的相对位置,从该分支的 Commits 被分析为 rebase 命令. 例如,如果用户希望从当前 HEAD 查看 5 个 Commits 在过去的命令是 git rebase -i HEAD~5.

如果你想写下新的承诺消息从滑板,这就足够了:

git reset --soft HEAD~3 &&
git commit

如果你想开始编辑新的承诺消息与现有承诺消息的折叠(即类似于什么一个 pick/squash/squash/.../squash git rebase -i 指示列表会开始你),那么你需要提取这些消息,并将它们转移到 git commit:

git reset --soft HEAD~3 && 
git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"

两种方法都将过去三项承诺分成一个单一的新承诺,相同的方式。 软重定义只会重新点头到最后一项承诺,你不想分解。 无论指数还是工作树都不会被软重定义所触摸,让指数在你新承诺所需的状态(即它已经有所有从你即将“扔掉”的承诺的变化)。

尝试了所有方法提到的这里. 但最终我的问题解决了通过遵循这个链接. https://gist.github.com/longtimeago/f7055aa4c3bba8a62197

$ git fetch upstream
$ git checkout omgpull 
$ git rebase -i upstream/master

 < choose squash for all of your commits, except the first one >
 < Edit the commit message to make sense, and describe all your changes >

$ git push origin omgpull -f

首先,我知道我的功能分支和当前主分支之间的承诺数量。

git checkout master
git rev-list master.. --count

然后,我创建另一个基于我的功能分支的分支,保持我的功能分支无触。

最后,我跑

git checkout my-feature
git checkout -b my-rebased-feature
git checkout master
git checkout my-rebased-feature
git rebase master
git rebase head^x -i
// fixup/pick/rewrite
git push origin my-rebased-feature -f // force, if my-rebased-feature was ever pushed, otherwise no need for -f flag
// make a PR with clean history, delete both my-feature and my-rebased-feature after merge

希望能帮忙,谢谢。

有人提到在 IntelliJ IDEA UI 上做得多容易:

转到 git 窗口 手动选择所有要融入一个的承诺. 右键单击 > Squash 承诺 > 编辑失败的承诺消息 点击左侧的分支名称 > 右键单击 > Push > Force Push

此分類上一篇