简体   繁体   English

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

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

Here is my git repo's current state (as visualised in GitX). 这是我的git repo的当前状态(如GitX中所示)。

分散的git历史

The '34e...' and 'c3d...' commits (the 'Implemented a global...' commented ones) are IDENTICAL. '34e ...'和'c3d ...'提交(注释为“ Implemented a global ...”)是相同的。 I confirmed this with git diff, and they even have identical commit times! 我用git diff确认了这一点,他们甚至有相同的提交时间! The only difference is their SHAs. 唯一的区别是它们的SHA。

I have no idea how I got my repo into this state. 我不知道我如何使我的仓库进入这种状态。 While I am no git pro, I have been using it for a while now and have become very comfortable with all the basics. 虽然我不是git pro,但我已经使用了一段时间,并且对所有基础知识都感到非常满意。 This has occurred out of the blue, and I wasn't experimenting with any git features or workflows that I hadn't used before, so I am rather confused. 这是突然发生的,我没有尝试过以前从未使用过的任何git功能或工作流程,所以我很困惑。

No one else has committed anything to the remote, so I can change history there, but a solution not involving that would be better. 没有人向远程计算机提交任何内容,因此我可以在那里更改历史记录,但是不涉及远程日志记录的解决方案会更好。

I could just do the normal merge or rebase of master and origin/master, but I am uncomfortable with that as the history will then show 2 identical commits. 我可以对master和origin / master进行正常的合并或变基,但是我对此感到不舒服,因为历史记录将显示2个相同的提交。

Is it possible to checkout origin/master and then rebase all the commits starting at 'a4a...' onto origin/master, and then switch master to this new HEAD? 是否可以检出origin / master,然后将所有从'a4a ...'开始的提交重新设置为origin / master,然后将master切换到新的HEAD? (basically leaving the 'c3d...' commit hanging by itself, which doesnt matter as its the dupe) (基本上让'c3d ...'提交本身挂起,这与它的重复无关紧要)

1) So whats the preferred way to fix this? 1)那么解决此问题的首选方法是什么?
2) Any ideas how this happened? 2)任何想法这是怎么发生的? Anyone else seen it before? 有人看过吗?

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

git reflog master : git reflog主

Bender:mt-d-styles tyson$ git reflog master Bender:mt-d-styles泰森$ git reflog master
9579294 master@{0}: commit: Added debug only console printing to test image view 9579294 master @ {0}:提交:已添加仅调试控制台打印以测试图像视图
1155228 master@{1}: commit: Added new marker interface that custom cells can imp 1155228 master @ {1}:提交:添加了自定义单元格可以添加的新标记界面
a4ab788 master@{2}: commit: Added a new StyledRootElement that automatically app a4ab788 master @ {2}:提交:添加了一个新的StyledRootElement,它可以自动应用
c3db784 master@{3}: commit: Implemented a global technique for styling all exist c3db784 master @ {3}:提交:实现了一种用于存在所有样式的全局技术
34e1ab6 master@{4}: commit: Implemented a global technique for styling all exist 34e1ab6 master @ {4}:提交:实施了一种用于存在所有样式的全局技术
8519fb1 master@{5}: commit: Extended the remove method to give callers access to 8519fb1 master @ {5}:提交:扩展了remove方法,使调用者可以访问
30aeee6 master@{6}: commit: Added a new factory method based Side Swipe View con 30aeee6 master @ {6}:提交:添加了一个新的基于工厂方法的Side Swipe View con

git reflog origin/master : git reflog来源/主版

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

EDIT 2: 编辑2:
git log --format=raw --decorate --graph --all : 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 
|

The Cause : You probably did some history rewriting. 原因 :您可能重写了一些历史记录。 If the commits where exactly identical, the SHA would automatically be the same. 如果提交完全相同,则SHA将自动相同。 What you see in you UI is not the commit date, but the author date. 在用户界面中看到的不是提交日期,而是作者日期。 Run git log --format=raw --decorate ̵-graph --all to get more details. 运行git log --format=raw --decorate ̵-graph --all以获得更多详细信息。 I guess you will see that the commit date of your local version is a later date. 我想您会看到本地版本的提交日期是以后的日期。 That is caused by history rewriting, usually amending or rebasing. 这是由历史重写(通常是修改或重新定型)引起的。

The Solution : If you know how to go back, you could just try pulling with rebase – if the commits really are identical, git should realize this and only add one commit. 解决方案 :如果您知道如何返回,则可以尝试使用rebase拉–如果提交确实相同,则git 应该意识到这一点,并且只添加一个提交。 If you don't know how to go back, just rebase master onto origin/master , cutting at c3db784817: 如果您不知道如何返回,只需将master重新设置为origin/master ,然后在c3db784817处剪切:

git rebase --onto origin/master c3db784817 master

@Your question in the comments: @您在评论中的问题:

How I know you amended from the reflog: 我如何知道您从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

Your master branch was at 34e1ab6 , after you created a commit. 创建提交后,主分支位于34e1ab6 Then you pushed this commit. 然后,您推送了此提交。 Then your master branch moved to c3db784 – a commit with the same message, and your git client says the reason for this was commit . 然后,您的master分支移至c3db784 -具有相同消息的提交,并且git客户端说这是commit的原因。 Since there was no branch head movement in between, this smells a lot like an amend. 由于两者之间没有分支头运动,因此闻起来很像修改。 The command line client would say commit (amend) though. 命令行客户端会说是commit (amend)

And your log tells me that you did the first commit at unix time 1364529327 (2013-03-28 20:55:27) and then amended it at unix time 1364539365 (2013-03-28 23:42:45). 而且您的日志告诉我,您是在unix时间1364529327 (2013-03-28 20:55:27)进行的第一次提交,然后在unix时间1364539365 (2013-03-28 23:42:45)进行了修改。 (And that you probably live in the US ;) (而且您可能居住在美国;)

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

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