【发布时间】:2011-06-18 13:17:45
【问题描述】:
我的问题是我更改了一个文件,例如:README,添加了一个新行 'this for my testing line' 并保存了文件,然后我发出了以下命令:
git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: README
#
no changes added to commit (use "git add" and/or "git commit -a")
git add README
git commit -a -m 'To add new line to readme'
我没有将代码推送到 GitHub。现在我想取消这个提交。
为此,我使用了
git reset --hard HEAD~1
但是我从 README 文件中丢失了新添加的行 'this for my testing line'。 这不应该发生。我需要内容在那里。 有没有办法保留内容并取消我的本地提交?
【问题讨论】:
-
听起来你绝对不是在要求
git revert,它创建了一个新的提交,它与恢复的提交的反向差异。重置只是将您当前的分支指向不同的提交,在这种情况下,是您想要“忘记”的提交之前的那个。 -
注意:可能值得一提的是,如果您将消息留空,
git-commit可能会中止,因此如果您还没有真正完成可能有帮助的提交。
标签: git git-reset git-commit