Reputation: 59
Git commits e.g. I do six commits for a specific code file, is there a way for me to switch to my previous commits?
Upvotes: 0
Views: 84
Reputation: 770
Yes! There is always a way to do that.
You can make use of git log --oneline
to see all your commits.
Then copy the commits id, and use git checkout the+commit_id
to move to the commits you wish.
To go back to where you were, use git checkout the+branchname
Upvotes: 0
Reputation: 30212
Sure.... you can use their IDs... which you can get from git log.
git checkout some-id
You can also refer to a branch.
git checkout some-branch~3 #3 revisions behind some-branch
Or you can use HEAD
(in other words, your current position) as a reference
git checkout HEAD~3 # go back 3 revisions from where I am right now
All 3 forms will set up in detached HEAD state
, just in case. So you will have to checkout a branch later when you want to go back to normal.
Upvotes: 1