简体   繁体   中英

Git Hard Reset on a single file confusion

I am a newbie in git and currently trying out various combinations to understand git.

I cloned my repository which had two files. Now i made changes to one file (let's say "first.txt") and committed it to staging.

After this step i wanted to reset the "first.txt" to its remote counterpart such that no git commit history related to "first.txt" was present for my branch. Now if I use -

git checkout origin/master first.txt

This will just replace my file with the remote file but git commit history for that file was not be replaced.

If i use -

git reset --hard <sha1 commit id>

then it restores the branch to that particular commit and all commits made there after are lost.

Now what i wanted to understand was if there is any method by which we can hard reset a file such that its entire content and commit history is restored to its remote's content and history.

Thanks for taking out time to read my question !

If downvoting then kindly let me know what else could have been improved in the question.

Thanks

Commits represent changes of entire repository. If you want to work with restoring single file to its some other version checking out and commiting is the best option. Otherwise you have to restore entire repo to its remote like this:

git reset --hard origin/master
git pull origin master

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