0

Ok, so I am new to git and scared to do anything that would permanently mess things up. I did a commit yesterday, then pulled from the remote repo, and have messed around on some of the files. Now I want to go back to everything I had right after I committed and before I pulled, but I want to make sure that I don't mess up anything on the remote branch, and dont want to lose anything that I committed. What should I do? I know there are a lot of questions like this, but I wanted to ask specifically for what I am trying to do. Also, once I get back to the last commit, can I just pull again from the remote branch?

1 Answers1

0

If you really don't want to mess anything locally, you could simply duplicate (copy) your entire repo in a new folder, and try that in said new folder.


I dont want to lose anything that I committed

First, make a branch where you are (that will references your last commmits)

 git branch tmp

From "HEAD and ORIG_HEAD in Git":

"pull" or "merge" always leaves the original tip of the current branch in ORIG_HEAD.

git reset --hard ORIG_HEAD

If you did any more merge after the pull, then ORIG_HEAD wouldn't have the right information anymore, and you would have to get the commit before the pull in the git reflog.

I want to make sure that I don't mess up anything on the remote branch, and

The git reset is a local command applied to your local clone: the remote repo isn't aware of it.

Once you have reset, you can git cherry-pick the last few commits you see with git log tmp.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • may I ask what the difference is between HEAD and ORIG_HEAD? – user3507586 Jun 15 '14 at 04:32
  • @user3507586: http://stackoverflow.com/a/967611/6309 "`ORIG_HEAD` is previous state of `HEAD`, set by commands that have possibly dangerous behavior, to be easy to revert them". – VonC Jun 15 '14 at 04:34
  • okay, what I did was 'git reset --hard 8b22b3b' which reset to that commit I think? but when I run 'git status' I see a bunch of untracked files and I'm no sure where they came from. Is this normal? – user3507586 Jun 15 '14 at 05:29
  • @user3507586 yes, it is: see the comment of http://stackoverflow.com/q/4327708/6309 (and its answer) Again making a copy of the repo *before* those commands is a good idea. – VonC Jun 15 '14 at 05:33