1

Here is all the need:

I have a remote branch (fix branch) called /fix/version-1.x which have two commits:

  • First commit done by user A
  • Second commit by user B (Me)

It turned out that this branch is not correct (more precisely my second commit) : there was some implementation error on one file

As first step :

1- I have downloaded this branch (with the two commit)

so as first reaction i made a simple checkout for this file to the previous commit (the first one) as there was no implementation error there .

2- I checked out the first commit (only for this file)

git checkout 'commit' file/to/restore

3- I got a 'detached HEAD' with git branch command

4- I made the cahnge for this file (correction)

5- git add file/to/restore

6- git status OK

7- I made a commit with a new msg git commit -m "solve implementation error problem"

when I push my local branch to the remote server
8- git push remote fix/version-1.x

It tell me that there is every thing is up to date (already updated) nothing to do !!!

but when I'm working without checking out the file to the previous state (the fist commit), ie i made the change directly on this branch and made a commit then push to the remote server every thing is working correctly and i have the new commit (third one ) on the remote server.

It seems that the problem comes from this detached head ? I 'm doing wrong here ?

elDiablo
  • 51
  • 4
  • What do you mean by "downloaded" in step 1? Also `git checkout 'commit' file/to/restore` should *not* result in a detached HEAD, unless you have already been in detached HEAD before. If you do your changes in detached HEAD the branch will not get updated. Therefore everything is indeed up to date. – michas Jan 06 '15 at 15:33
  • thx @michas for the help, - downlooad => git clone the remote repository - No I was working with the fix branch => git checkout -b fixbranch remote/fixbranch – elDiablo Jan 07 '15 at 10:50

1 Answers1

0

It seems that the problem comes from this detached head

Indeed. git checkout 'commit' -- file/to/restore should have reset only that specific file without detaching the HEAD.
That detached HEAD status must have come from step1.

What step1 should look like would be:

git clone url/remote/repo/
cd repo
git checkout fix/version-1.x

That local branch will be automatically linked to its upstream branch.
From git checkout man page:

git checkout <branch>

If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to:

git checkout -b <branch> --track <remote>/<branch>

Then you can proceed with git checkout 'commit' -- file/to/restore

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • >Indeed. git checkout 'commit' -- file/to/restore should have reset only that specific file without detaching the HEAD. Yes, This is what I'm looking for but it turn out with a detached HEAD >hat detached HEAD status must have come from step1. I'm using git clone + git checkout the fix branch – elDiablo Jan 07 '15 at 10:57