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


当前回答

在问题上,可以是双重的“最后”是什么意思。

* commit H0
|
* merge
|\
| * commit B0
| |
| * commit B1
| | 
* | commit H1
| |
* | commit H2
|/
|

可以使用折扣,但以不同的方式,然后在其他提到的答案:

首頁 / 首頁 / 2

这将向您展示选择选项(如其他答案中提到的):

pick B1
pick B0
pick H0

pick B1
pick B0
s H0

在保存和退出后,将执行命令,然后在H1之后,这意味着它将要求你重新解决冲突(在那里,主将是H1首先,然后积累命令,当它们被应用)。

退缩结束后,您可以选择失败的 H0 和 B0 消息:

* commit squashed H0 and B0
|
* commit B1
| 
* commit H1
|
* commit H2
|

P.S. 如果你只是做一些重新设置到BO:(例如,使用重新设置 - 混合,这里详细解释 https://stackoverflow.com/a/18690845/2405850):

git reset --mixed hash_of_commit_B0
git add .
git commit -m 'some commit message'

其他回答

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

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

希望能帮忙,谢谢。

让我们说 n 真的很大. 你不想处理每一个承诺. 你只是想要一个名为 new_feature_branch 的新分支,其中有 1 承诺和所有旧_feature_branch 的变化。

git checkout main 

# will contain changes all changes from old_feature_branch 
git checkout -b new_feature_branch 

# get all changes from old_feature_branch and stage them
for f in $(git --no-pager diff --name-only old_feature_branch ) ; do git checkout fencing -- $f ; done

git commit -m "one commit message"

方法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

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

许多地方的承诺,混合了多种合并,从大师,最终推到远程,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。

Anomies 答案很好,但我对此感到不安全,所以我决定添加几张屏幕截图。

步骤 0: git log

查看你在哪里与 git log. 最重要的是,找到第一个 commit 的 commit hash 你不想 squash。

此分類上一篇

步骤一:转动

在我的案例中,执行 git rebase -i(你的哈希):

$ git rebase -i 2d23ea524936e612fae1ac63c95b705db44d937d

步骤2:选择 / 切割你想要的东西

在我的情况下,我想把所有的承诺,这是第一次在时间上。 订单是从第一到最后,所以正如在 git log。 在我的情况下,我想:

此分類上一篇

步骤 3: 调整消息(s)

如果您只选出一个承诺,并解除其余的承诺,您可以调整一个承诺消息:

此分類上一篇

一旦你保存这个(:wq),你已经完成了。