Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In git, how do you revert a file back to 3 commits ago?

Tags:

git

git-revert

I changed an image file in git and it was 2 commits ago. How do I go back to 2 previous commits ago?

What is the easiest method of doing this file revert via the command line with the least amount of commands required?

like image 777
Patoshi パトシ Avatar asked Jan 08 '14 17:01

Patoshi パトシ


People also ask

How do I revert to a previous version of a file in git?

In case you are using the Tower Git client, you can use the reset command right from a commit's contextual menu. And in case you made a mistake: simply hit CMD+Z to undo the reset and restore the removed commits!

How do I revert a last 3 commit?

The syntax of the command is git revert --no-commit <commit> . Thus, to revert the three commits of the bug fixes done, we need to do as follows. Thus, the repository in Git is now in the state before committing the bug1 fixed . We have used the sha1 name of the commits to revert each commit.

Can we revert multiple commits in git?

Tip: When you revert multiple commits, it's best to revert in order from newest to oldest. If you revert commits in a different order, you may see merge conflicts. Click History. Right-click the commit you want to revert and click Revert Changes in Commit.


1 Answers

Just check out the old version of that file:

git checkout HEAD~2 -- path/to/file

Or more explicit:

git checkout commit-id -- path/to/file
like image 55
poke Avatar answered Sep 23 '22 19:09

poke