我的问题是我已经更改了一个文件,例如: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”。 这种情况不应该发生。我需要内容在那里。是否有一种方法可以保留内容并取消本地提交?