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


当前回答

要避免在重定向同一分支中的承诺时不得不解决任何合并冲突,您可以使用下列命令:

git rebase -i <last commit id before your changes start> -s recursive -X 我們

要将所有承诺分成一个,当您被要求编辑将合并的承诺时(在旗帜上),更新所有但第一个行动,从选择到分解,如其他答案中所建议。

在这里,我们使用合并策略(旗帜)回归和战略选项(X)我们的,以确保历史上后来的承诺赢得任何合并冲突。

注意:不要把这与我们做别的事情的 git rebase 混淆。

引用: git rebase recursive merge 策略

其他回答

我如何将我的最后一个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 reset --soft HEAD~5

git commit -m “委托信”

git push 起源分支 --force-with-lease

您可以使用 git merge --squash 为此,这比 git rebase -i 略有优雅。

警告: 首先,请确保您完成工作 - 检查 git 状态是干净的(因为 git 重新设置 - 硬将抛弃错误和错误的变化)

然后:

# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12

# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}

# Commit those squashed changes.  The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
git commit

git merge 的文档详细描述了 --squash 选项。


更新:这个方法的唯一真正优点,比克里斯·约翰森(Chris Johnsen)在他的回答中提出的更简单的吉特重新设置 --soft HEAD~12 &&吉特承诺是,你会得到承诺的消息,以每一个承诺的消息,你正在破坏。

如何回答与此类工作流相关的问题?

许多地方的承诺,混合了多种合并,从大师,最终推到远程,PR和合并到大师由审查员(是的,开发人员将更容易合并 - 经过大师,但团队认为这将减缓过程)。

我没有在这个页面上看到这样的工作流(这可能是我的眼睛)如果我正确地理解复制,多种融合将需要多种冲突解决方案。

所以,这似乎为我们工作。

git pull master git checkout -b new-branch git checkout -b new-branch-temp edit and commit a lot locally, merge master regularly git checkout new-branch git merge --squash new-branch-temp // puts all changes in stage git commit 'one message to rule them all' git push Reviewer does PR and merges to master。

方法1 如果你有很多承诺

git rebase -i master 然后按一下键盘“i”来编辑

你会看到这样的:

pick etc1
pick etc2
pick etc2

用“f”取代“ pick”这个词,然后按 esc y :wq。

pick etc1 //this commit will the one commit
f etc2
f etc2

按下这个命令

git push origin +head

方法2 如果你有少数承诺,你可以这样做去删除承诺,你必须这样做去删除你的第二承诺等等。

git reset --soft HEAD^1 // or git reset --soft head~1
git commit --amend //then press `:wq` 
git push -f

方法 3 如果你已经有一个承诺,你不想提交另一个承诺更多

git add files...
git commit --amend  //then press `:wq`
git push origin +head