tags:

views:

81

answers:

3

I am working on a file where the my current commit ended up being bad and I want to go back to earlier commits for a specific file?

I did a search it looks like no one has answered a similar question (how to roll back changes in a file in a previous commit in git)....

Hopefully a simple answer?

+3  A: 

git reset <commit hash> <filename>

dgnorton
You should probably mention that this needs to be followed by 'git add <filename>' and 'git commmit', assuming that the outcome is what is desired.
ebneter
She probably wants `git checkout` instead, as per @progo’s answer.
Aristotle Pagaltzis
@Aristotle, you're right...@progo's answer is better.
dgnorton
A: 

Well, the main thing that is probably confusing you is that git keeps track of complate versions of the entire repository, not just one file. So what you have to do is figure out which version of the repository has the version of the file you are looking for, and roll back to that.

If you just want that old version of the file, but want all the other changes that the repository took in the meantime, you have to do a bit more work.

For complex operations like rollbacks, I'd generally suggest using one of the GUI tools (like git gui), as they let you visualize better what you are getting ready to do.

T.E.D.
+3  A: 
git checkout <commit-id> file(s)

It will overwrite easily so beware with your file wildcards, which do can cover several files at once. For help, you can check out the git log messages with the wanted files as a filter:

git log <file>

Will show only those commits with log messages that involve the <file> searched.

progo
yes, thanks, I want a specific file, so it sounds like I use the log (or go through my hosted repository I guess) and get that big long string and the name of the file....thanks
Angela