简体   繁体   English

无法 git 拉取:在 ff4e1bf(最新 ec2 实例列表)中删除文件并在 HEAD 中修改。 文件的版本 HEAD 留在树中

[英]Unable to git pull: file deleted in ff4e1bf (Latest ec2 instance list.) and modified in HEAD. Version HEAD of file left in tree

I tried to delete a file in my git repo, and now I can't do a git pull anymore.我试图在我的 git 存储库中删除一个文件,现在我不能再执行 git 拉取操作了。

The file I'm trying to delete is: aws_scripts/source_files/aws_accounts_list/aws_accounts_list.csv我要删除的文件是: aws_scripts/source_files/aws_accounts_list/aws_accounts_list.csv

Now when I do a git pull, I get:现在,当我执行 git 拉动时,我得到:

CONFLICT (modify/delete): aws_scripts/source_files/aws_accounts_list/aws_accounts_list.csv deleted in ff4e1bf (Latest ec2 instance list.) and modified in HEAD. Version HEAD of aws_scripts/source_files/aws_accounts_list/aws_accounts_list.csv left in tree.

The full error says:完整的错误说:

 git pull origin develop
From github.com:bluethundr/jf_cloud_scripts
 * branch            develop    -> FETCH_HEAD
error: could not apply ff4e1bf... Latest ec2 instance list.
Resolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".
Could not apply ff4e1bf... Latest ec2 instance list.
CONFLICT (modify/delete): aws_scripts/source_files/aws_accounts_list/aws_accounts_list.csv deleted in ff4e1bf (Latest ec2 instance list.) and modified in HEAD. Version HEAD of aws_scripts/source_files/aws_accounts_list/aws_accounts_list.csv left in tree.
Auto-merging aws_scripts/python/aws_tools/ec2_mongo.py

How can I make git realize the file is supposed to be deleted and do the git pull I need?我怎样才能让 git 意识到文件应该被删除并做我需要的 git 拉动?

This sort of thing is why I encourage those new to Git to avoid git pull : the pull command is a convenience command that combines two other Git commands.这就是为什么我鼓励 Git 的新手避免git pull : pull 命令是一个方便的命令,它结合了其他两个 Git 命令。

The base commands are:基本命令是:

  • git fetch , meaning obtain new commits from someone else , followed by git fetch ,意思是从其他人那里获得新的提交,然后是
  • the second command: combine the work I did in my repository with my new commits, with the work they did in their repository with their new commits .第二个命令:将我在存储库中所做的工作与我的新提交结合起来,将他们在存储库中所做的工作与他们的新提交结合起来

It's true that the first step—the git fetch —is not very useful on its own, because getting their commits is equivalent to just getting a bunch of packages delivered.确实,第一步git fetch并没有多大用处,因为获得他们的提交就相当于只是交付了一堆包。 Until you open them up and use what's in them , they just sit around.在您打开它们并使用其中的内容之前,它们只是坐在那里。 So you do need two steps.所以你确实需要两个步骤。 But I think it's better, for various reasons, to do them on your own at first.但我认为,出于各种原因,首先自己做会更好。 (Not everyone agrees with me.) (不是每个人都同意我的观点。)

The second command is where things can get sticky.第二个命令是事情变得棘手的地方。 You choose which second command to use: the default is git merge , but you can (and, based on messages above, did) select git rebase instead.您选择要使用的第二个命令:默认为git merge ,但您可以(并且根据上面的消息,确实) select git rebase代替。 Either method means combine my work with their work;任何一种方法都意味着将我的工作与他们的工作结合起来; the difference is how the combining is done:不同之处在于组合是如何完成的:

  • git merge combines everything in one step, leaving all the original commits untouched. git merge将所有内容合并在一个步骤中,使所有原始提交保持不变。 Since history, in Git, is commits, this preserves exactly what you did, and exactly what they did.自历史以来,在 Git 中,就是提交,这完全保留了您所做的以及他们所做的。

  • git rebase has the effect of copying your earlier commits to different, new-and-one-hopes-improved, commits. git rebase具有将您之前的提交复制到不同的、新的和一个希望改进的提交的效果。 Your Git then abandons your original commits in favor of these new and?improved?您的 Git 然后放弃您的原始提交,转而支持这些新的和改进的? commits.提交。 Since history, in Git, is the commits in the repository, this leaves you with a more-readable history.由于历史,在 Git 中,存储库中的提交,这为您留下了更具可读性的历史。 It's kind of a fake history though: it implies that you did your work after they did theirs, rather than in parallel with theirs.不过,这有点像历史:这意味着您在他们完成了他们的工作之后才完成了您的工作,而不是与他们的工作并行

There are some strong reasons to prefer one or the other in some cases.在某些情况下,有一些强有力的理由偏爱其中一种。 In your particular case, probably none of those reasons apply, so either method is fine.在您的特定情况下,这些原因可能都不适用,因此任何一种方法都可以。

Now, the actual problem here is that during the merge-or-rebase, Git has come across the following situation:现在,这里的实际问题是,在 merge-or-rebase 期间,Git 遇到了以下情况:

  • You removed a file entirely.您完全删除了一个文件。
  • They changed the file.他们更改了文件。

Git isn't sure how to combine these actions. Git 不确定如何组合这些操作。 Perhaps you want to keep the changed file, or just the lines they put in and remove all the other lines.也许您想保留更改的文件,或者只保留他们放入的行并删除所有其他行。 Perhaps you want the file to stay removed.也许您希望文件保持被删除。 Git isn't willing to pick one answer on its own. Git 不愿意自己选择一个答案。 So, it stops in the middle of the operation.因此,它在操作中间停止。

Your job is to finish the operation.你的工作是完成手术。 There are a lot of details, but probably you just want to keep the file gone.有很多细节,但可能您只想保留文件。 To do that, tell Git keep the file gone by removing it and git add ing the result, or using git rm on the file (which I find easier to remember, and has the same effect, but sometimes generates a mild complaint).为此,请告诉 Git 通过删除文件git add结果,或使用git rm在文件上保留文件(我发现它更容易记住,但有时会产生同样的抱怨,但效果温和)。 Then tell Git to continue the operation, whatever it was.然后告诉 Git 继续操作,不管它是什么。

In your particular case, the operation is a rebase, so to continue it after resolving the conflict, run:在您的特定情况下,该操作是一个变基,因此要在解决冲突后继续它,请运行:

git rebase --continue

This will go on to copy any additional commits if needed.如果需要,这将 go 复制任何其他提交。 Each step can have its own merge conflict (this is one reason some prefer the merge method);每个步骤都可以有自己的合并冲突(这是一些人更喜欢合并方法的原因之一); if so, you may have to resolve multiple conflicts over multiple commits.如果是这样,您可能必须解决多个提交的多个冲突。

If the second step had been git merge , you would need git merge --continue to continue the merge operation.如果第二步是git merge ,则需要git merge --continue继续合并操作。 (In truly ancient versions of Git, there is no --continue here and you must run git commit instead, but unless you work with really old Git versions you are unlikely to encounter this.) (在真正古老的 Git 版本中,这里没有--continue并且您必须运行git commit ,但除非您使用真正旧的 Git 版本,否则您不太可能遇到这种情况。)

Once the second operation is all done, your git pull is finished.一旦完成第二个操作,您的git pull就完成了。

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

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