My issue is I have changed a file eg: README, added a new line ' this for my testing line ' and saved the file, then I issued the following commands
(我的问题是我已经更改了一个文件,例如: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'
I didn't push the code to github, Now I want to cancel this commit.
(我没有将代码推送到github,现在我想取消这个提交。)
For this I used
(为此我用过)
git reset --hard HEAD~1
But I lost the newly added line ' this for my testing line ' from the README file.
(但是我从README文件中丢失了新增的“ 我的测试行 ”。)
This should not happen. (这不应该发生。)
I need the content to be there. (我需要内容。)
Is there a way to retain the content and cancel my local commit? (有没有办法保留内容并取消我的本地提交?)
ask by Amal Kumar S translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…