gpt4 book ai didi

git - 在 `git format-patch` ,`git am` , `git pull` 之后在 git 历史中双重提交

转载 作者:太空狗 更新时间:2023-10-29 13:34:05 30 4
gpt4 key购买 nike

我在我的电脑上开发代码,我的计算节点很少。

为了让我的程序保持同步,我决定使用 git。以前,我以一种单向模式使用它来“下推”从 PC 到计算节点的更改。但是时不时遇到计算节点特有的小bug,现场修复。与在 PC 上编写并提交可能会或可能不会修复所有问题的更改相比,测试和开发更容易。

我决定使用 git 实用程序将更改向上游发送回 main 代码库。

我编写了修复程序。在计算笔记上提交,使用git format-patch origin。将补丁发送到我的 PC 并使用 git am 应用它。到目前为止,一切看起来都很甜蜜。

但是,当我在计算节点上使用 git pull 时,它再次从源中 pull 带有补丁的提交,并且 git log 显示两个具有相同评论和作者的提交。

我使用的命令有误,还是我的工作流程有缺陷?或者这是可以接受的? (不过我觉得不太好)。

在这两种情况下,我都在 master 分支上工作。

git pull计算节点:

commit 68710f82ddb2b2f191a9c29f088423853032a851  <--- git pull enforced merge
Merge: ce19df4 609b82b
Author: luk32 <luk32@computing.node>
Date: Fri Dec 13 20:39:28 2013 +0100

Merge branch 'master' of PC:~/projects/_cmake

commit 609b82bc96f88da956869cec2953e8621cbdcd93 <--- 2nd git pull after git am
Author: luk32 <luk32@computing.node>
Date: Fri Dec 13 20:35:23 2013 +0100

Changed to worki with MathGL version 2. Broken version 1 compatibility!

commit ce19df4760519eaf42269461f7bdcf94b65bdc48 <--- on-site fix
Author: luk32 <luk32@computing.node>
Date: Fri Dec 13 20:35:23 2013 +0100

Changed to worki with MathGL version 2. Broken version 1 compatibility!

commit ccc5b8a1854e4ca4089cf4c0945baff990288557 <--- after previous git pull
Author: lukas <luk32@PC>
Date: Mon Jan 16 10:33:11 2012 +0100

skeleton changed to introduce project stacks

git log 在 PC 上看起来不错:

commit 609b82bc96f88da956869cec2953e8621cbdcd93
Author: luk32 <luk32@computring.node>
Date: Fri Dec 13 20:35:23 2013 +0100

Changed to worki with MathGL version 2. Broken version 1 compatibility!

commit ccc5b8a1854e4ca4089cf4c0945baff990288557
Author: lukasz kucharski <luk32@PC>
Date: Mon Jan 16 10:33:11 2012 +0100

skeleton changed to introduce project stacks

编辑:computing.node:~/projects/_cmake$ git log --decorate --graph --oneline master

*   68710f8 (HEAD, master) Merge branch 'master' of PC:~/projects/_cmake
|\
| * 609b82b (origin/master, origin/HEAD) Changed to work with MathGL version 2. Broken version 1 compatibility!
| * ccc5b8a skeleton changed to introduce project stacks
* | ce19df4 Changed to work with MathGL version 2. Broken version 1 compatibility!
|/
* 35d2eaa (origin/pushee) added eigen3 find module
* 39f4937 small bugfixes and slight changes in the reporting of what's going on

最佳答案

将补丁应用到 origin 之后,在运行 git pull 之前,您的历史记录如下所示:

  * 609b82b (origin/master, origin/HEAD) Changed to work with MathGL version 2. Broken version 1 compatibility!
* ccc5b8a skeleton changed to introduce project stacks
* | ce19df4 (HEAD, master) Changed to work with MathGL version 2. Broken version 1 compatibility!
|/
* 35d2eaa (origin/pushee) added eigen3 find module
* 39f4937 small bugfixes and slight changes in the reporting of what's going on

您的第一个提交 ce19df435d2eaa 作为其父项。当您应用补丁时,您进行了第二次提交,609b82b,将 ccc5b8a 作为其父级。因为他们有不同的 parent ,所以他们是不同的提交并且有不同的散列。提交的标识是

  • 存储库的快照(在第二次提交时有所不同,因为存储库现在包含来自 ccc5b8a 的更改)。
  • 提交消息、作者、时间(相同,因为您使用了 format-patcham)。
  • 父提交(第二次提交不同)。

那么,git pull 是做什么的呢?我不会向新的 git 用户教授 pull,因为它很容易混淆。这取决于您所在的分支,并且仅在将其设置为跟踪分支时才有效(master 可能是,但可能不是您的其他分支,除非您自己设置它们)。它做了两件事:

  • 获取远程更改(与 git fetch 相同)。
  • 尝试将远程分支与当前分支 merge (与 git merge 相同)。如果您的本地分支设置为跟踪分支,它只知道尝试 merge 哪个分支。

merge 令人困惑。它尝试进行快进 merge (read more here),但不能。因此,相反,它创建一个 merge 提交,将本地分支作为一个父级,将远程分支作为另一个父级,你会得到这个:

*   68710f8 (HEAD, master) Merge branch 'master' of PC:~/projects/_cmake
|\
| * 609b82b (origin/master, origin/HEAD) Changed to work with MathGL version 2. Broken version 1 compatibility!
| * ccc5b8a skeleton changed to introduce project stacks
* | ce19df4 Changed to work with MathGL version 2. Broken version 1 compatibility!
|/
* 35d2eaa (origin/pushee) added eigen3 find module
* 39f4937 small bugfixes and slight changes in the reporting of what's going on

虽然这对于 git merge 来说是合理的,但这不是您想要的。谁在乎您首先针对 35d2eaa 进行了提交?你真的只是想让 master 指向与 origin/master 相同的提交。您现在可以到达那里:

git checkout master
git stash # If you have any uncommitted changes
git reset --hard origin/master
git stash pop

然后您的历史记录将看起来像这样,就像您想要的那样。

* 609b82b (HEAD, master, origin/master, origin/HEAD) Changed to work with MathGL version 2. Broken version 1 compatibility!
* ccc5b8a skeleton changed to introduce project stacks
* 35d2eaa (origin/pushee) added eigen3 find module
* 39f4937 small bugfixes and slight changes in the reporting of what's going on

关于git - 在 `git format-patch` ,`git am` , `git pull` 之后在 git 历史中双重提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20594197/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com