Home > Blockchain >  Git show is left behind in some obscure way
Git show is left behind in some obscure way

Time:02-16

I do on git version 1.8.3.1

git checkout develop --
git fetch origin develop
git reset --hard FETCH_HEAD
git diff FETCH_HEAD HEAD
git diff

The diffs show no differences .. good. If I edit my file then it is the same as in GitLab on the remote .. good.

If I do

git show origin/develop:<my file>

then I see an earlier version.

I get the same for

git show remotes/origin/develop:<my file>

CodePudding user response:

git rev-parse origin/develop and git rev-parse remotes/origin/develop both point at the same commit. git rev-parse FETCH_HEAD points at a different commit.

You used git reset --hard FETCH_HEAD as a surrogate for git reset --hard origin/devleop but, for whatever reason, FETCH_HEAD was not at origin/develop.

FETCH_HEAD and ORIG_HEAD change with the last command and can change out from under you. Use git reset --hard origin/develop to be sure.

git reset --hard FETCH_HEAD
git diff FETCH_HEAD HEAD

Note that this check is tautological. If you just reset your current branch (develop) to FETCH_HEAD it will be at FETCH_HEAD. If you expect your current checkout to be at origin/develop check git diff origin/develop.

Use git log --graph --decorate to see the true state of your repository and what commits develop and origin/develop point at.

CodePudding user response:

This is the problem:

git version 1.8.3.1 ...

git fetch origin develop

Running:

git fetch origin

on Git 1.8.3.1 will do what you want, but running:

git fetch origin develop

on Git 1.8.3.1 won't, because the action you wish to have happen was not put into Git until 1.8.4.

You can run:

git fetch origin develop:refs/remotes/origin/develop

if you're unwilling to just run:

git fetch origin

for some reason. Or, of course, you can upgrade Git (you really should upgrade to at least Git 2.23, to get the new git switch and git restore commands).

  •  Tags:  
  • git
  • Related