Git Revert Error Message?

时光总嘲笑我的痴心妄想 提交于 2020-01-02 04:47:12

问题


While trying to revert a commit I made to my repository of my .emacs.d folder I get the following message:

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.

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.


回答1:


Q. What conflict?

The conflict from merging the reverse patch of that revision, when later revisions changed the same lines of code: a merge conflict

Edit If you are reverting the latest commit, this means that you had local changes (refer to git status). Don't forget that you can have staged and unstaged local changes. To easily see all local changes, use

   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.

You can use

git mergetool

to resolve the conflicts with more user-friendly tools like Meld, KDiff3, Gvim etc.




回答2:


You're making a confusion between untracked files and unstaged files.

  • Untracked files are unknown to Git, you never git added them (i.e. git status will show them in the Untracked 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 the Changes not staged for commit: section). These changes will be included in the next commit if you run git commit -a, but not if you run git commit without -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.



来源:https://stackoverflow.com/questions/8281803/git-revert-error-message

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!