0

I had the following scenario:

I have my local branch and committed changes to the local branch. Say my local branch is tracking the master branch from repository.

local ---> origin/master

Consider the file as a/b/c.d I have modified contents of this my file in my local branch.

Now I wished to check out how things would behave with the original c.d with my other code changes.

So I did :

git checkout origin/master a/b/c.d

Now I wish to go back to the original file in my local branch commit.

I did:

git reset a/b/c.d
git checkout -- a/b/c.d

I got back my original file (present in my local branch).

Is it the right way of doing things or there is a better way to discard the changes and get the file in my local branch after:

git checkout origin/master a/b/c.d

Could not find a scenario after googling.

Thanks

gudge
  • 1,053
  • 4
  • 18
  • 33
  • 1
    You may use `git checkout -f` to restore all the contents of your current branch, if I understand you correctly. – Ixanezis Apr 16 '14 at 06:11
  • @lxanezis Thanks. This works. I tested it out. – gudge Apr 16 '14 at 06:12
  • As long as you have no other changes you're going to lose, just reset the branch. `git reset --hard HEAD` or you can just reset the specific files `git reset HEAD a/b/c.d` – Jason Coco Apr 16 '14 at 06:13
  • After : git reset HEAD a/b/c.d One has to do git checkout -- a/b/c.d – gudge Apr 16 '14 at 06:17
  • I was looking for a singe command to combine: git reset a/b/c.d git checkout -- a/b/c.d – gudge Apr 16 '14 at 06:19

0 Answers0