当 git 说一个文件“需要更新”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2660977/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does it mean when git says a file "needs update"?
提问by rofrankel
I can't for the life of me find any decent explanation of the "[file]: needs update" message that git sometimes spits out from time to time. Even the official git FAQ has explaining this marked as a TODO. If someone could explain A) what it means; and B) how to fix it, I would be extremely grateful.
对于 git 有时会不时吐出的“[文件]:需要更新”消息,我一生都找不到任何体面的解释。甚至官方的 git FAQ 也将其解释为 TODO。如果有人可以解释 A) 这意味着什么;B) 如何修复它,我将不胜感激。
采纳答案by Michael Mrozek
It means you're trying to merge changes from somewhere, but the changes include modifications to a file that's dirty (currently modified in your working tree). You need to commit your outstanding changes, or stash them, pull/rebase/merge/whatever you're doing to update, and unstash
这意味着您正在尝试从某处合并更改,但这些更改包括对脏文件的修改(当前在您的工作树中修改)。您需要提交未完成的更改,或将它们隐藏起来,拉取/变基/合并/无论您在做什么以进行更新,并取消隐藏
回答by lomza
As others have pointed out, needs updatemessage means that the file is dirtyor, in other words, outdated. But instead of doing reset and starting all over again, what can be done is simply git status
and then git add <file>
ifit's on the changedlist. Because you could already add the file before, but then changed it. This happened to me, and with this simple add
I have solved the problem.
正如其他人所指出的,需要更新消息意味着文件已脏,或者换句话说,已过时。但是,与其进行重置并重新开始,还可以做的很简单git status
,git add <file>
如果它在已更改的列表中。因为您之前可能已经添加了该文件,但随后又对其进行了更改。这发生在我身上,用这个简单的add
我解决了这个问题。
回答by NXT
Log into your production/destination server, cd
to the directory containing your application and execute those two commands.
登录到您的生产/目标服务器,cd
到包含您的应用程序的目录并执行这两个命令。
1. Reset to the latest version
1.重置为最新版本
WARNING, this will delete all your changes:
git reset --hard HEAD
警告,这将删除您的所有更改:
git reset --hard HEAD
2. Pull the changes
2. 拉取更改
git pull origin master
git pull origin master
回答by tripleee
Like the answer to the linked other question says, the message simply means that you have outstanding changes. You also get this e.g. if you stage some changes with git add
, then change your mind and do git reset HEAD file
with the intention of starting over.
就像链接的其他问题的答案所说的那样,该消息仅表示您有出色的更改。您也会得到这个,例如,如果您使用 进行一些更改git add
,然后改变主意并git reset HEAD file
打算重新开始。
回答by proxy
This error can occur when rebase process make additional changesto files that is not on target branch.
当 rebase 进程对不在目标分支上的文件进行额外更改时,可能会发生此错误。
For me the tricky part was with .gitattributes
file in my repo. New binary file type was added in another branch but it's handling was forced as text file. When file was downloaded from repo by git, EOLs (it's binary value bytes actually) was replaced - resulting in binary difference.
对我来说,棘手的部分是.gitattributes
我的回购中的文件。在另一个分支中添加了新的二进制文件类型,但它的处理被强制为文本文件。当 git 从 repo 下载文件时,EOL(实际上是二进制值字节)被替换 - 导致二进制差异。
Adding new entry to handle new file type as binary and retrying whole process solved problem for me.
添加新条目以将新文件类型作为二进制处理并重试整个过程为我解决了问题。
回答by ThinkDigital
In my case, I kept getting
就我而言,我一直得到
assets/ElipseThree.png: needs update
You must edit all merge conflicts and then
mark them as resolved using git add
I had those files in my directory, but they had been renamed in my current branch. So to fix, I ran
我的目录中有这些文件,但它们已在我当前的分支中重命名。所以为了修复,我跑了
$ git mv assets/ElipseThree.png assets/elipseThree.png
$ git add assets/elipseHalfFull.png
$ git rebase --continue
and it allowed me to continue
它让我可以继续