Unable to push reverted file to repository after git reset

Note - I am new to understanding the git reset command, so I am not sure if it is the right command for what I want to do, which is very simple.

I wanted to undo the changes made in the last git push. So, I ran the following reset command to go back to the desired commit hash (one before the undesired commit hash)-

git reset <last desired commit hash> <file name>

After this, there were no changes to file as such (working directory). But, git status showed that the file had been modified.

 modified:   <filename>

On doing git stash now, the working directory file was modified. But, I do not see an option to push the changes to remote repository. Git pull also shows no changes.


You can solve your doubts in your approach with this.

  • git reset <last desired commit hash> <file name> . This will restore your desired file( <file name> ) into the version specified by <last desired commit> . And you will still be remained in the current branch.

  • If the file you specified had any difference between the version you had and the version you restored, soon after you executed previous command this kind of a text should appear. Unstaged changes after reset: M <file name>

  • You can verify it by the following command. git diff <file name> . Then it will show the change happened.

  • git stash will remove any un-staged commit. So obviously after git stash you can't commit or push since there are no any changes. And git pull would not work either. Reason is your local branch will not go behind with commits by git reset . So it has all the commits in remote branch. So there's no new commits to be pulled by git pull .

  • You can try followings. Do git stash apply . So your file will again go to the state of last desired commit. Verify the changes by git diff <file name> . Then commit & push.

  • If your expected change was not there when you check the diff, the problem should be with some other thing, not version controlling. :))

  • 链接地址: http://www.djcxy.com/p/49802.html

    上一篇: 什么时候应该使用git pull

    下一篇: 无法在git重置后将恢复的文件推送到存储库