好了,我已經試過你認爲你做,做什麼你寫
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) –