简体   繁体   中英

Git File push to remote undo

I have a file that I made changes to locally and then committed and pushed to remote.I actually realized that they were incorrect changes and want only that particular file to go back to its original state (and not undo entire commit), will git checkout filename work? or should I delete the file locally and pull from master?

You could fix your commit by performing any additional changes you may need and then commiting them with git commit --ammed . You could then use git push --force origin to "override" your previous commit.

Note that this may break any work other have done on top of this commit, so you should use it with great care.

You can get the file in your work tree back to its previous state using something like

git checkout HEAD^ -- path/to/file

(This assumes the file was broken in the most recent commit. You could use HEAD~2 instead of HEAD^ to go back 2 commits, etc.)

Then you can treat this like any other change; if nothing else needs to be changed, you can go ahead and add/commit/push.

Since you have already pushed the original commit, I recommend you not use --amend . Doing so would require a force push, which would then cause trouble for everyone else who has the ref in their clone of the repo. It's possible to recover, so if you really want to coordinate with the whole team to slightly clean up the history, you could ; but I doubt it would be worth it.

这对我有用(也许是因为我的特殊情况,但只是张贴它可以帮助任何人!) - > 1)撤消我对文件的更改2)在主文件和我的文件副本之间做差异,看看是否没有差异3)提交和推送文件从Pull Request Files Changed消失了(这就是我想要的)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM