最佳答案
我的问题是我更改了一个文件,例如:README,添加了一个新行“这是我的测试线”并保存了文件,然后我发出了以下命令:
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文件中新添加的行“这是我的测试线”。这不应该发生。我需要内容在那里。有没有办法保留内容并取消我的本地提交?