Git:在本地重新绑定之后重复提交,然后拉取 [英] Git: duplicate commits after local rebase, then pull

查看:178
本文介绍了Git:在本地重新绑定之后重复提交,然后拉取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个功能分支A,它是我的开发分支之前的一个提交:

  3(develop,origin / develop)
| 2(A,origin / A)某些功能分支提交
| /
1一些提交

然后我重新开发A( git checkout A git rebase develop ),所以我得到:

  2'(A)一些功能分支提交
|
3(develop,origin / develop)
| 2(origin / A)某些功能分支提交
| /
1一些提交



<现在我不能再推送 A origin ,因为Git会拒绝非快进提交。它告诉我要先拉动远程更改。



当我这样做然后按下时,我最终得到以下历史记录:



$ p $ 4(A,origin / A)合并的原点/ A转换为A
| \
2'|一些功能分支提交
| |
3 | (develop,origin / develop)
| 2(origin / A)某些功能分支提交
| /
1一些提交

我最终得到了一个包含 2 提交两次的历史记录 - 技术上不同的提交,尽管他们做了同样的事情。



问题


  1. 如何防止发生这种情况?我如何在远程回购上镜像我的本地rebase操作?

  2. 我该如何弥补这种情况?


解决方案

    什么是清理历史并显示唯一提交的最优雅的方式? >
  1. 重写是重写历史记录 - 为了避免麻烦,不要重新绑定推送的内容。

  2. code> push --force ,同时检出 A origin / A 历史将被您的 A 版本覆盖。请注意,此后需要其他开发人员进行手动干预。

    Background:

    I have a feature branch A that is one commit ahead of my development branch:

    3   (develop, origin/develop)
    | 2 (A, origin/A) some feature branch commit
    |/
    1   some commit
    

    Then I rebase A on develop (git checkout A, git rebase develop), so I get:

    2'  (A) some feature branch commit
    |
    3   (develop, origin/develop)
    | 2 (origin/A) some feature branch commit
    |/
    1   some commit
    

    Now I can no longer push A to origin as Git will reject a non-fast forward commit. It tells me to first pull the remote changes.

    When I do so and then push, I end up with the following history:

    4   (A, origin/A) merged origin/A into A
    |\
    2'| some feature branch commit
    | |
    3 | (develop, origin/develop)
    | 2 (origin/A) some feature branch commit
    |/
    1   some commit
    

    I end up with a history containing the 2 commit twice -- technically different commits although they do the same thing.

    Questions

    1. How can I prevent this from happening? How can I mirror my local rebase operation on the remote repo?
    2. How can I remedy this situation? What would be the most elegant way to clean up the history and show only one commit?

    解决方案

    1. A rebase is rewriting history - to avoid trouble don't rebase things that are pushed.

    2. You can push --force while A is checked out. origin/A history will be overwritten with your version of A. Note that this will require manual intervention from other developers in their repos afterwards.

    这篇关于Git:在本地重新绑定之后重复提交,然后拉取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆