繁体   English   中英

Git远程跟踪分支与具有不同SHA的相同提交的本地分支不同

[英]Git remote tracking branch diverged from local branch with identical commits with different SHAs

这是我的git repo的当前状态(如GitX中所示)。

分散的git历史

'34e ...'和'c3d ...'提交(注释为“ Implemented a global ...”)是相同的。 我用git diff确认了这一点,他们甚至有相同的提交时间! 唯一的区别是它们的SHA。

我不知道我如何使我的仓库进入这种状态。 虽然我不是git pro,但我已经使用了一段时间,并且对所有基础知识都感到非常满意。 这是突然发生的,我没有尝试过以前从未使用过的任何git功能或工作流程,所以我很困惑。

没有人向远程计算机提交任何内容,因此我可以在那里更改历史记录,但是不涉及远程日志记录的解决方案会更好。

我可以对master和origin / master进行正常的合并或变基,但是我对此感到不舒服,因为历史记录将显示2个相同的提交。

是否可以检出origin / master,然后将所有从'a4a ...'开始的提交重新设置为origin / master,然后将master切换到新的HEAD? (基本上让'c3d ...'提交本身挂起,这与它的重复无关紧要)

1)那么解决此问题的首选方法是什么?
2)任何想法这是怎么发生的? 有人看过吗?

编辑:
git diff c3db784817 34e1ab666a :未输出任何内容。

git reflog主

Bender:mt-d-styles泰森$ git reflog master
9579294 master @ {0}:提交:已添加仅调试控制台打印以测试图像视图
1155228 master @ {1}:提交:添加了自定义单元格可以添加的新标记界面
a4ab788 master @ {2}:提交:添加了一个新的StyledRootElement,它可以自动应用
c3db784 master @ {3}:提交:实现了一种用于存在所有样式的全局技术
34e1ab6 master @ {4}:提交:实施了一种用于存在所有样式的全局技术
8519fb1 master @ {5}:提交:扩展了remove方法,使调用者可以访问
30aeee6 master @ {6}:提交:添加了一个新的基于工厂方法的Side Swipe View con

git reflog来源/主版

Bender:mt-d-styles泰森$ git reflog origin / master
34e1ab6 refs / remotes / origin / master @ {0}:通过推送进行更新
8519fb1 refs / remotes / origin / master @ {1}:通过推送进行更新
495e0ef refs / remotes / origin / master @ {2}:通过推送进行更新
c5fec81 refs / remotes / origin / master @ {3}:通过推送进行更新
cba1e0f refs / remotes / origin / master @ {4}:通过推送进行更新
9ee1ffb refs / remotes / origin / master @ {5}:通过推送进行更新
68ee429 refs / remotes / origin / master @ {6}:通过推送进行更新
0e2d199参考/远程/来源/ master @ {7}:通过推送进行更新
8a4de84 refs / remotes / origin / master @ {8}:通过推送进行更新

编辑2:
git log --format = raw --decorate --graph --all

*  commit c3db7848171f396c5a595a35dd6b609c119f9e84 
| tree 998e9749546d05178798c8a462d3eff02a111f4c 
| parent 8519fb17e77b8ae865e071772ae652316df8822a 
| author Tyson <tyson> 1364529327 +0800 
| committer Tyson <tyson> 1364539365 +0800 
|  
|     Implemented a global technique for styling all existing MT.D element backg 
|  


| * commit 34e1ab666a81dde7582ee9e31bfa961420d38f55 (origin/master) 
|/  tree 38f9e0c3d936c702fdcd18d215a2f0a88280893b 
|   parent 8519fb17e77b8ae865e071772ae652316df8822a 
|   author Tyson <tyson> 1364529327 +0800 
|   committer Tyson <tyson> 1364529327 +0800 
|    
|      Implemented a global technique for styling all existing MT.D element bac 
|

原因 :您可能重写了一些历史记录。 如果提交完全相同,则SHA将自动相同。 在用户界面中看到的不是提交日期,而是作者日期。 运行git log --format=raw --decorate ̵-graph --all以获得更多详细信息。 我想您会看到本地版本的提交日期是以后的日期。 这是由历史重写(通常是修改或重新定型)引起的。

解决方案 :如果您知道如何返回,则可以尝试使用rebase拉–如果提交确实相同,则git 应该意识到这一点,并且只添加一个提交。 如果您不知道如何返回,只需将master重新设置为origin/master ,然后在c3db784817处剪切:

git rebase --onto origin/master c3db784817 master

@您在评论中的问题:

我如何知道您从reflog进行了修订:

c3db784 master@{3}: commit: Implemented a global technique for styling all exist
34e1ab6 master@{4}: commit: Implemented a global technique for styling all exist

创建提交后,主分支位于34e1ab6 然后,您推送了此提交。 然后,您的master分支移至c3db784 -具有相同消息的提交,并且git客户端说这是commit的原因。 由于两者之间没有分支头运动,因此闻起来很像修改。 命令行客户端会说是commit (amend)

而且您的日志告诉我,您是在unix时间1364529327 (2013-03-28 20:55:27)进行的第一次提交,然后在unix时间1364539365 (2013-03-28 23:42:45)进行了修改。 (而且您可能居住在美国;)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM