4

这是我的 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 tyson$ git reflog master
9579294 master@{0}:commit:添加了仅调试控制台打印以测试图像视图
1155228 master@{1}:commit:添加了自定义单元格可以
影响 a4ab788 master的新标记界面@{2}:commit:添加了一个新的 StyledRootElement,它会自动应用
c3db784 master@{3}:commit:实现了一个全局技术来设置所有存在的样式
34e1ab6 master@{4}:commit:实现了一个全局技术来设置所有存在的样式
8519fb1 master @{5}:commit:扩展了 remove 方法,让调用者可以访问
30aeee6 master@{6}:commit:添加了一个新的基于工厂方法的 Side Swipe View con

git reflog origin/master

Bender:mt-d-styles tyson$ 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 refs/remotes/origin/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 
|
4

1 回答 1

6

The Cause: You probably did some history rewriting. If the commits where exactly identical, the SHA would automatically be the same. 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. 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. If you don’t know how to go back, just rebase master onto origin/master, cutting at c3db784817:

git rebase --onto origin/master c3db784817 master

@Your question in the comments:

How I know you amended from the 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创建提交后,您的主分支位于。然后你推送了这个提交。然后你的主分支移动到c3db784- 一个带有相同消息的提交,你的 git 客户端说原因是commit. 由于中间没有分支头移动,这闻起来很像修正。命令行客户端会说commit (amend)

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

于 2013-03-30T00:23:49.860 回答