Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git switching between commits

I read on here and searched a lot but didn't find the answer, so Is there a way to switch between commits like you do with branches.Let's say I have these commits: a;b;c where c is my last commit, can I switch back to commit a? Or you have to do a git diff and modify the files manually?

like image 276
Uffo Avatar asked Jan 07 '12 19:01

Uffo


2 Answers

Just type git checkout a. Or perhaps more usefully, git checkout -b mybranch a, to checkout a as a new branch mybranch.

If you want to revert b and c, you can use git revert, or to remove them entirely from your current branch's history, you could git rebase -i a and throw them out.

Even if you were going to use git diff, you wouldn't have to do anything manually. Check out git format-patch, git apply, and git am to automate creating and applying patches.

like image 85
Carl Norum Avatar answered Sep 25 '22 23:09

Carl Norum


You can create a branch from the revision you want to work from. The revision number can be seen using

   git log

Branch out from the previous revision

 git branch -f branchname rev
like image 35
Shraddha Avatar answered Sep 25 '22 23:09

Shraddha