Git Revert";无法还原,因为您有未合并的文件;

Git Revert";无法还原,因为您有未合并的文件;,git,revert,Git,Revert,我做了一个简单的例子来编写一些GIT函数的文本。存储库中只有一个文本文件: 1 添加并提交更改 然后更改了txt。提交至: 1 2 添加并提交更改 Git log给出了以下结果: commit 00e59212a6... .. second commit commit 7c319d587.... .. first commit 此时,我想返回到第一次提交(但我不想使用“reset--hard”) git revert 7c319d587 但我收到了以下错误消息: revert is n

我做了一个简单的例子来编写一些GIT函数的文本。存储库中只有一个文本文件:

1
添加并提交更改

然后更改了txt。提交至:

1
2
添加并提交更改

Git log给出了以下结果:

commit 00e59212a6...
..
second commit

commit 7c319d587....
..
first commit
此时,我想返回到第一次提交(但我不想使用“reset--hard”)

git revert 7c319d587
但我收到了以下错误消息:

revert is not possible because you have unmerged files
hint: Fix them up in the work tree, and the use "git add/rm
hint: as appropriate to mark resolution and make a commit
我是GIT新手-在我使用SVN之前,您可以非常简单地处理这些事情,所以我想知道这些简单的事情是否需要GIT中的一些步骤


非常感谢您的帮助。

好吧,我已经尝试了您认为您所做的,完全按照您所写的做了

cd /tmp
mkdir so35588521
cd so35588521
git init
# Initialized empty Git repository in /tmp/so35588521/.git/
touch 1
echo "1" > 1
git add .
git commit -m "first"
# [master (root-commit) 173f431] first
#  1 file changed, 0 insertions(+), 0 deletions(-)
# create mode 100644 1
touch 2
touch 3
git add .
git commit -m "second"
# [master a9fdcc9] second
#  2 files changed, 0 insertions(+), 0 deletions(-)
#  create mode 100644 2
#  create mode 100644 3
git log
# commit a9fdcc9338c9b3de25c211580a35ab63d1d57c2e
# Author: Me and my email
# Date:   Tue Feb 23 22:46:50 2016 +0100
git revert a9fd
# [master dd5a86e] Revert "second"
# 2 files changed, 0 insertions(+), 0 deletions(-)
# delete mode 100644 2
# delete mode 100644 3
正如你所看到的,一切都进行得很顺利。因此,我想,啊哈!她/他一定做了别的事情,却忘了在上面提及。哦,好吧,我会弄清楚她/他用我的水晶球做了什么。它到处乱扔有什么意义

所以,合并,git说。然后,让我们做一个分支,并尝试将它与我们的主分支合并

git checkout -b a_branch
# Switched to a new branch 'a_branch'
echo "2" > 1
git status
# On branch a_branch ...
git add .
git commit -m "third"
# [a_branch 96d3a7a] third
#  1 file changed, 1 insertion(+), 1 deletion(-)
git checkout master
# Switched to branch 'master'
echo "3" > 1
git add .
git commit -m "fourth"
# [master 7f72eec] fourth
#  1 file changed, 2 insertions(+), 1 deletion(-)
#### Now we have first commit, and second, and revert second, and two commits: third on **a_branch** branch and fourth on **master**. 
git merge a_branch
# Auto-merging 1
# CONFLICT (content): Merge conflict in 1
# Automatic merge failed; fix conflicts and then commit the result.
# *Oh DANG* whyy? Git stop, don't do that it hurts, revert!
git revert last_commit_id_from_git_log
# error: revert is not possible because you have unmerged files.
# hint: Fix them up in the work tree, and then use 'git add/rm <file>'
# hint: as appropriate to mark resolution and make a commit.
# fatal: revert failed
# *Git nope!*
git签出-b a_分支机构
#切换到新分支“a_分支”
回声“2”>1
git状态
#在a_分支上。。。
git添加。
git提交-m“第三个”
#[a_分行96d3a7a]第三
#1个文件已更改,1个插入(+),1个删除(-)
切换到主分支
#切换到“主”分支
回声“3”>1
git添加。
git提交-m“第四”
#[master 7f72eec]第四
#1个文件已更改,2个插入(+),1个删除(-)
####现在我们有了第一次提交、第二次提交和第二次恢复,以及两次提交:第三次提交在**a_分支**分支上,第四次提交在**master**上。
git合并a_分支
#自动合并1
#冲突(内容):将冲突合并到1中
#自动合并失败;修复冲突,然后提交结果。
#*哦,该死的*为什么?停下来,别那么做会痛的,回复!
git从git日志还原上次提交的id
#错误:无法还原,因为您有未合并的文件。
#提示:在工作树中修复它们,然后使用“git add/rm”
#提示:根据需要标记解析并进行提交。
#致命:还原失败
#没有*
现在,这只是我的猜测,我希望这会带来一点幽默。如果这不是你所做的,你能告诉我们你所做的确切步骤吗?因为我无法复制你所犯的错误,因此,我感到无法自责

编辑:

既然OP坚持说肯定没有做分支

rm *
rm -rf .git
git init
echo -e "line one\n" > 1
git add .
git ci -m "first"
echo -e "line two\n" >> 1
git ci -a -m "second"
git log
# commit 23d710610d98c1046844870557208f335e76a933
# Author: ME <me@home>
# Date:   Tue Feb 23 23:31:28 2016 +0100
#
#     second
# 
# commit 22873fb5fbf06d80a1779fe6740060c660d68714
# Author: ME <me@home>
# Date:   Tue Feb 23 23:30:47 2016 +0100
#
#    first

git revert "first"
# fatal: bad revision 'first'  # but OK i assume You used id, so,
git revert 22873fb5fbf06d80
# error: could not revert 22873fb... first
# 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'
rm*
rm-rf.git
初始化
echo-e“第1行\n”>1
git添加。
git ci-m“第一”
echo-e“第二行\n”>>1
git ci-a-m“秒”
吉特日志
#提交23d710610d98c1046844870557208f335e76a933
#作者:我
#日期:周二2月23日23:31:28 2016+0100
#
#第二
# 
#提交22873fb5fbf06d80a1779fe6740060c660d68714
#作者:我
#日期:周二2月23日23:30:47 2016+0100
#
#首先
git还原“第一”
#致命:错误的修订版“第一”#但好吧,我想你使用了id,所以,
吉特恢复22873fb5fbf06d80
#错误:无法还原22873fb…首先
#提示:解决冲突后,标记更正的路径
#提示:使用“git add”或“git rm”
#提示:并使用“git commit”提交结果
啊哈,现在我明白了!那就是比扎尔

好的,我检查过了,实际上你是对的,在我的
git--version
2.6.3上,我可以复制这种行为。实际上,我认为你在这里遇到了非常棘手的情况。发生的事情是,在你第二次提交后,git存储了你对文件
test.txt
所做的更改,并保留了这些更改。现在你告诉他了(它?)要
git revert first\u commit\u id
,它实际上创建了test.txt文件。我不能确定,但这对我来说似乎是个小错误


但是!如果您在第二次提交中添加了文件,例如
test2.txt
(这样您将在git存储库中有两个版本的文件),那么
还原
工作正常。

听起来像是添加了一个文件(例如编辑器备份文件)。请尝试
git status
查看git认为正在进行的操作。git status-->在分支主机上;您当前正在还原提交7c319d587。(修复冲突并运行“git revert--continue”)(使用git revert--abort取消还原操作);未合并的路径:(使用“git reset Heat..”取消还原);由他们删除:test.txt;提交时未添加任何更改(使用“git add”和或“git commit-a”):谢谢:1)创建了一个txt文件/added/committed 2)在该文件中添加了第二行/saved/added/committed 3)git revert“first commit”“-->Get error:不可能,因为您有未合并的文件4)我从未更改或创建过新的分支5)分支主机上的git status-->;您当前正在恢复提交7c319d587。(修复冲突并运行“git revert--continue”)(使用git revert--abort取消还原操作);未合并的路径:(使用“git reset Heat..”取消存储);他们钻研:test.txt;没有任何修改添加到提交(使用“Git Addio”和“git提交-A”),让我只添加它来回答,所以您可以确认您确实这样做。我仍然不能复制您所做的。因此,因为我可以复制它,并考虑这个小错误,我会发出一个Git维护者的bug请求(在检查出血边缘Git)之后,除非您想: