好了,我已经试过你认为你做,做什么你写
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
你可以看到 - 一切顺利。因此,我认为,AHA!她/他必须做别的事情,忽略在SO上提及它。哦,我会弄清楚他/她用水晶球做了什么。它在什么地方铺设无用。
所以,合并,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!*
现在,这只是我的猜测,并带来了一点幽默感,所以我希望。如果这不是你所做的,你能告诉我们确切的步骤吗?由于我无法复制您正在使用的错误,因此我觉得无法完成。
编辑:
由于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 <[email protected]>
# Date: Tue Feb 23 23:31:28 2016 +0100
#
# second
#
# commit 22873fb5fbf06d80a1779fe6740060c660d68714
# Author: ME <[email protected]>
# 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'
Ahaaa,现在我知道了!而那......是比萨饼。
好的,我检查了一下,你是对的,在我的git --version
2.6.3我可以复制这种行为。其实,我认为你在这里进入了一个非常角落的案例。发生了什么事是,在你的第二次提交后,git存储了你对文件test.txt
所做的更改并保留了这些更改。现在你告诉他(它?)到git revert first_commit_id
哪个实际上创建了文件test.txt。我无法确定,但这对我来说似乎是一个小错误。
但是!如果你在第二次提交 - 添加文件,例如test2.txt
(所以你会有两个文件版本在git仓库中),然后revert
工程。
听起来像其他东西添加了一个文件(例如编辑器备份文件)。试试'git status'来获得git认为正在发生的事情。 – slothbear
git status - >在分支主机上;您正在恢复提交7c319d587。 (修复冲突并运行“git revert --continue”)(使用git revert --abort取消恢复操作); unmerged paths :(使用“git reset Heat ..”来取消);由他们删除:test.txt;没有更改添加到提交(使用“git add”和或“git commit -a) –