git revert中的"them"和"us"是谁? [英] Who is `them` and `us` in a `git revert`?

查看:117
本文介绍了git revert中的"them"和"us"是谁?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git revert期间我无法理解谁usthem在这些冲突中,所以我真的不知道这里发生了什么:

I can't make sense of who us and them are in these conflicts during a git revert, so I don't really know what's happening here:

git revert some_commit_hash

然后git status显示以下冲突:

deleted by them: path/to/file1.h
both modified:   path/to/file2.h
deleted by them: path/to/file1.cpp
deleted by them: path/to/test_file1.cpp
added by us:     path/to/file3.h
deleted by them: path/to/file4.h
added by us:     path/to/file5.h

谁是我们"?谁是他们"?

Who is "us"? Who is "them"?

更新:请注意,我要还原的提交是一个非常大的合并提交.

Update: note that the commit I'm reverting is a very large merge commit.

不重复:

  1. 因为它无法阐明谁是usthem:
  2. 因为它涵盖了mergerebase而不是revert,并且git经常根据操作使用相同的术语来表示相反的内容:
  3. 因为它没有提及我们"和他们" - Git-恢复还原,冲突
  1. because it doesn't clarify who is us and them: GIT: How dangerous is "deleted by us" conflict?
  2. because it covers merge and rebase but NOT revert, and git frequently uses the same terms to mean opposite things depending on the operation: Who is "us" and who is "them" according to Git?
  3. because it doesn't mention "us" and "them" - Git - reverting a revert, conflicts

推荐答案

TLDR;

跳到最底端以获取结果和结论.

TLDR;

Jump to the very bottom for the results and conclusion.

关于:

然后git status显示以下冲突:

deleted by them: path/to/file1.h
both modified:   path/to/file2.h
deleted by them: path/to/file1.cpp
deleted by them: path/to/test_file1.cpp
added by us:     path/to/file3.h
deleted by them: path/to/file4.h
added by us:     path/to/file5.h

我做了一些实验,并观察了以下内容.

I did some experimenting, and observed the following.

首先,对于任何重新设置或合并冲突,我通常只手动解决两个已修改文件path/to/file2.h中的冲突.然后,我添加了所有文件并完成了还原:

First, I manually resolved only the conflicts in the both modified file, path/to/file2.h, as normal for any rebase or merge conflict. I then added all files and finished the revert:

git add -A
git revert --continue

接下来,我观察到所有标有删除的文件以及所有标有由我们添加的文件在我的文件系统上存在/存在.因此,还原没有删除任何文件.接下来,我想知道:哪些提交创建了这些文件?要查看此内容,请运行以下内容():

Next, I observed that all files marked with deleted by them, as well as all files marked with added by us, were present / in existence on my file system. So, the revert deleted none of them. Next, I wanted to know: which commit created these files? To see this, run the following (source):

git log --diff-filter=A -- path/to/file

这仅显示创建该文件的单个commit_hashgit log commit_hash.我对每个由他们删除由我们添加的文件做了一次一次:

This shows the git log commit_hash for just the one single commit_hash which created this file. I did this one-at-a-time for each file which was deleted by them or added by us:

git log --diff-filter=A -- path/to/file1.h        # added by the commit I reverted
git log --diff-filter=A -- path/to/file1.cpp      # added by the commit I reverted
git log --diff-filter=A -- path/to/test_file1.cpp # added by the commit I reverted
git log --diff-filter=A -- path/to/file3.h        # added by a later commit
git log --diff-filter=A -- path/to/file4.h        # added by the commit I reverted
git log --diff-filter=A -- path/to/file5.h        # added by a later commit

我发现,如上所述,其中4个文件是由我还原的提交添加的. 注意,这意味着它们是由提交some_commit_hash本身添加的,而不是由我运行git revert some_commit_hash时创建的还原提交添加的.那么,如果我还原该提交,为什么它们仍然存在?好吧,事实证明,后来发生的提交,我们称为later_commit_hash,发生在some_commit_hash之后,触及了所有6个文件,修改了其中4个并创建了2个.

I found that 4 of the files, as indicated above, were added by the commit I reverted. Note, this means they were added by the commit some_commit_hash itself, NOT by the revert commit which was created when I ran git revert some_commit_hash. So, why did they still exist if I reverted that commit? Well, it turns out, a later commit, which we will call later_commit_hash, which happened AFTER some_commit_hash, touched all 6 of those files, modifying 4 of them and creating 2 of them.

将上述文件按删除的文件由我们添加的分组:

# deleted by them:
path/to/file1.h
path/to/file1.cpp
path/to/test_file1.cpp
path/to/file4.h

# added by us:
path/to/file3.h
path/to/file5.h

现在指示哪个文件是通过哪个提交添加的:

Now indicate which file was added by which commit:

# deleted by them / added by the commit I reverted (`some_commit_hash`)
path/to/file1.h
path/to/file1.cpp
path/to/test_file1.cpp
path/to/file4.h

# added by us / added by a later commit (`later_commit_hash`)
path/to/file3.h
path/to/file5.h

因此,您可以看到他们删除的文件是我还原的提交中添加的,这意味着还原该提交将删除这些文件!因此,them表示正在还原的提交,some_commit_hash,而us表示在HEAD的其余提交.

So, you can see that deleted by them files were added by the commit I reverted, which means that reverting that commit will delete those files! So, them refers to the commit being reverted, some_commit_hash, while us refers to the remaining commits at HEAD.

冲突是later_commit_hash触及了被他们删除"的那四个.文件,因此不允许git revert some_commit_hash删除它们.并且,由我们添加"的2个文件在some_commit_hash之前不存在,因此冲突在于它们在还原后不应该存在,但它们确实存在,因为它们是由later_commit_hash创建的.

The conflict was that later_commit_hash touched those 4 "deleted by them" files, so the git revert some_commit_hash wasn't allowed to delete them. And, the 2 "added by us" files did NOT exist prior to some_commit_hash, so the conflict was that they shouldn't have existed after the revert, but they did, because they were created by later_commit_hash.

我解决的方法是手动删除所有这6个文件:

The solution I did is I manually deleted all those 6 files:

rm path/to/file1.h
rm path/to/file1.cpp
rm path/to/test_file1.cpp
rm path/to/file3.h
rm path/to/file4.h
rm path/to/file5.h

然后我将该更改作为新的提交提交

then I committed this change as a new commit:

git add -A
git commit

但是,我可以将其重置为还原提交之前的位置,然后先还原为later_commit_hash,然后再还原为some_commit_hash,然后有效地将这些更改按顺序回滚,例如这个:

However, I could have instead reset back to the location prior to the revert commit and reverted later_commit_hash first, followed by reverting some_commit_hash second, effectively rolling these changes back in order, like this:

git reset --hard HEAD~  # WARNING! DESTRUCTIVE COMMAND! BE CAREFUL.
git revert later_commit_hash
git revert some_commit_hash
# should result in no conflicts during both of those reverts now

结果和结论:

无论哪种情况,都要回答我自己的问题:

Results and Conclusion:

In either case, to answer my own question:

git revert some_commit_hash期间:

  1. 我们" =键入并运行git revert some_commit_hash时当前签出的提交(即:HEAD),并且:
  2. 他们" =您要还原的提交(与之相反或相反);即:是一个短暂的提交,它与some_commit_hash相反,以撤消some_commit_hash的更改,假设您运行命令git revert some_commit_hash.
  1. "us" = the currently-checked out commit (ie: HEAD) at the time you type and run git revert some_commit_hash, and:
  2. "them" = the (inverse or opposite of?) the commit you are reverting; ie: it is some ephemeral commit which is the opposite of some_commit_hash, in order to undo some_commit_hash's changes, assuming you run the command git revert some_commit_hash.

我仍然在为这个概念苦苦挣扎,但这就是要点.我认为,还原工作原理的确切机制将在这里真正弄清楚事情. 此答案可能会提供更多的见解,但我不理解.

I'm still struggling a bit with this concept but that's the gist of it. The exact mechanics of how revert works would really clarify things here I think. This answer may offer some more insight, but I don't understand it.

我也刚刚在此处添加了一个答案,以阐明我们"的意思.和他们" 我可以想到的所有4个git操作:git mergegit cherry-pickgit rebasegit revert:

I've also just added an answer to here to clarify "us" and "them" for all 4 git operations I can think of where this may happen: git merge, git cherry-pick, git rebase, and git revert: Who is "us" and who is "them" according to Git?

(自我注释):

需要看一下: http://ezconflict.com/en/flictsse12.html#x53-890001.7

这篇关于git revert中的"them"和"us"是谁?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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