Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

I want to access a commit I made last Saturday. How?

I committed some changes to my remote repository last Saturday that have since been edited by other guys on my team resulting in a body of code that's got some notes in it that no longer functions the way that it needs to.

I've done some pulling and rebasing on my local box and it's a ball of snot.

I want to access the code that I pushed up to my remote repository a couple of days ago. I'm under the impression that once I rebase my local branch, I'm stuck from that perspective.

But I'm wondering if there isn't a way to turn back time on the remote repository so I can access that commit, pull it down to my local box and be good to go.

How can I do that?
Avatar of Bruce Gust
Bruce Gust
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gelonida
if your branch is called dvl/mybranch
then you could type
git fetch origin  # just to be sure you're in sync with the remote server
git log origin/dvl/mybranch

Open in new window

in order to look at what history and commits you have on the server

if you are willing to loose all changes of your current branch , that you comitted on your local machine, then you can force your local branch to one of the commit ids of the git server (one of the commit ids that you found with the git log command)
by typing.

git stash  # just a safete measure to put save all your local non commited changes
git reset --hard <commit_id_you_want_to_be_on>
git push -f

Open in new window

As I said this will make you loose any local commits, but it seems this is what you want to do.

In if something goes wrong you have still small safet net and could recover some things with
git reflog

Open in new window

(at least as long as you don't type git gc)
Avatar of pepr

I suggest to use the gitk --all first. You will see the commit points with the messages and with the dates and authors.
Then you can mouse right-click the wanted line (the wanted commit) and choose "Create new branch" (means at the commit). Give it some name. Then you just right-click the green rectangle of the new branch and choose "Checkout this branch" -- now you have the sources in the working copy.
Of course, you can do it from command line, but I like the overview presented by the gitk.
Agree with @pepr. Whenever in any doubt, gitk is an excellent tool to visualize the version tree of your project.

I'm mostly a command line person and use almost no GUIs or IDEs. However gitk with the --all option is one of the few exceptions.

I still do most modifications to the version tree by command line.

For git I recommend:
using gitk --all to see visualize and try to understand
git reflog --date=iso to understand any issues with broken merges, failed rebases, etc and to idenify commits you were on your PC in the past
git rebase and git rebase --interactive are two commands which are one of the difficult and advanced git features but if you master them    
git reset --hard <commitid> to force a branch to a certain version