Git 恢复错误信息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8281803/
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
Git Revert Error Message?
提问by haziz
While trying to revert a commit I made to my repository of my .emacs.d folder I get the following message:
在尝试恢复我对 .emacs.d 文件夹的存储库所做的提交时,我收到以下消息:
haziz@haziz> git revert 7fe3f
error: could not revert 7fe3f0b... .emacs.d contents from ubuntu hp 15
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
What I am trying to do is reverse changes I made to my init.el file and have followed with another commit which I am trying to reverse. I would prefer to revert rather than reset --hard since as far as I know the latter completely erases the most recent commit. I would like to create a new commit so that I can possibly "revert" the revert.
我想要做的是反向更改我对我的 init.el 文件所做的更改,然后是另一个我试图反向的提交。我宁愿恢复而不是重置 --hard 因为据我所知后者完全删除了最近的提交。我想创建一个新的提交,以便我可以“还原”还原。
In other words what I am trying to do is this
换句话说,我想做的是这个
Git Commits [A]...[B]
would be reverted to
将恢复为
Git Commits [A]...[B]...[A']
Am I doing something wrong?
难道我做错了什么?
Edit:I tried doing a diff/merge as best as I could then another commit but then it still gives me this new error message:
编辑:我尝试尽可能地进行差异/合并,然后再进行一次提交,但它仍然给我这个新的错误消息:
haziz@haziz> git revert 7fe3f0ba3182b591f11c0b59e006dc6c990b7470
fatal: Your local changes would be overwritten by revert.
Please, commit your changes or stash them to proceed.
How do I tell it to ignore (but not delete) unstaged files, without resorting to a .gitigore file. I frankly don't care about most of the unstaged files which are emacs temp files etc.
我如何告诉它忽略(但不删除)未暂存的文件,而不求助于 .gitigore 文件。坦率地说,我不关心大多数未暂存的文件,即 emacs 临时文件等。
回答by sehe
Q.What conflict?
问:什么冲突?
The conflict from merging the reverse patchof that revision, when later revisions changed the same lines of code: a merge conflict
合并该修订的反向补丁时产生的冲突,当后来的修订更改了相同的代码行时:合并冲突
EditIf you are reverting the latestcommit, this means that you had local changes (refer to
git status
). Don't forget that you can have stagedand unstagedlocal changes. To easily see all local changes, usegit diff HEAD
编辑如果您要恢复最新提交,这意味着您进行了本地更改(请参阅
git status
)。不要忘记,您可以进行暂存和未暂存的本地更改。要轻松查看所有本地更改,请使用git diff HEAD
You should just open up the unmerged file (git status
) to see the conflicted file(s). You'll see the <<<<
, =====
, >>>>>
conflict markers soon enough.
您应该只打开未合并的文件 ( git status
) 来查看冲突的文件。您很快就会看到<<<<
, =====
,>>>>>
冲突标记。
You can use
您可以使用
git mergetool
to resolve the conflicts with more user-friendly tools like Meld, KDiff3, Gvim etc.
使用更友好的工具(如 Meld、KDiff3、Gvim 等)解决冲突。
回答by Matthieu Moy
You're making a confusion between untracked files and unstaged files.
您混淆了未跟踪的文件和未暂存的文件。
Untracked files are unknown to Git, you never
git add
ed them (i.e.git status
will show them in theUntracked files:
section).Unstaged files are tracked files which have local changes, which you did not stage for commit (i.e.
git status
will show them in theChanges not staged for commit:
section). These changes will be included in the next commit if you rungit commit -a
, but not if you rungit commit
without-a
.
Git 不知道未跟踪的文件,您从未
git add
编辑过它们(即git status
会在Untracked files:
部分中显示它们)。未暂存的文件是具有本地更改的跟踪文件,您没有暂存这些文件以进行提交(即
git status
会在Changes not staged for commit:
部分中显示它们)。如果您运行git commit -a
,这些更改将包含在下一次提交中,但如果您git commit
没有运行,则不会-a
。
It does not make sense to tell git to ignore unstaged changes: the changes are there, and they touch files that Git cares about.
告诉 git 忽略未暂存的更改是没有意义的:更改就在那里,并且它们会触及 Git 关心的文件。