简体   繁体   中英

How do I revert one file to its original state in git?

I have a few files I made changes to.

Then I committed it and realized I made a change to a file I didn't want to change. How can I get the file back to its original state? I am on a branch.

git checkout --file

didn't do anything at all.

git checkout filename

will work in most cases, unless you have a branch with the same name as a file. In either case,

git checkout -- filename

will be sufficient.

你需要一个空格--和你的文件名:

git checkout -- filename

Try

git checkout HEAD~ filename

instead.

git checkout HEAD~ filename

is the only one that worked for me

if you have not committed the change git restore filename

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