Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git-stash is moving my master branch

Tags:

git

git-stash

I'm trying to switch from a feature branch to master without losing my changes, and so I'm trying to git stash and then switch to master, but master is moving to my feature branch. Basically:

<feature*> $ git status
# On branch feature
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   hay.md
<feature*> $ git rev-parse --short HEAD
737b183 
<feature*> $ git rev-parse --short master
109b5f7 # This happens to be 4 commits ago
<feature*> $ git stash
Saved working directory and index state WIP on feature: 737b183 Some commit
HEAD is now at 737b183 Some commit
<feature> $ git rev-parse --short HEAD
737b183 
<feature> $ git rev-parse --short master
737b183 # WAT??!!!

Am I misunderstanding git-stash? Or maybe git as a whole? Or do I misunderstand the nature of the correspondence of perception and reality?

Update I just discovered it does the same thing in the case of a git reset.

<feature*> $ git status
# On branch feature
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   modified:   hay.md
<feature*> $ git rev-parse --short HEAD
737b183 
<feature*> $ git rev-parse --short master
109b5f7
<feature*> $ git reset --hard HEAD
HEAD is now at 737b183 Some commit
<feature> $ git rev-parse --short HEAD
737b183 
<feature> $ git rev-parse --short master
737b183 # Hm....

Another Update

It's only happening in one "instance" of the repo (I don't know the right git vocabulary), so I imagine there is something wonky in .git/. A bandaid solution is to delete the repo and clone it from the remote again, but I'd kind of like to know why it's happening.

Some more stuff

‹master› » git checkout feature
Switched to branch 'feature'
Your branch is ahead of 'master' by 1 commit.
  (use "git push" to publish your local commits)
‹feature› » echo "Hay" >> hay.md
‹feature*› » cat .git/HEAD
ref: refs/heads/feature
‹feature*› » cat .git/refs/heads/master
93d9d14b0f298ed28cc1520905768281f32d0929
‹feature*› » cat .git/refs/heads/feature
51410c5dcd679b8cf57a7dce2d17be7bbd121923
‹feature*› » git stash
‹feature› » cat .git/HEAD
ref: refs/heads/feature
‹feature› » cat .git/refs/heads/master
51410c5dcd679b8cf57a7dce2d17be7bbd121923
‹feature› » cat .git/refs/heads/feature
51410c5dcd679b8cf57a7dce2d17be7bbd121923
like image 447
Jake Avatar asked Nov 06 '13 19:11

Jake


1 Answers

I once noticed a similar behavior when I accidentally created both a branch and a tag called foo and git internally accessed a commit by name and took the wrong one.

Did you maybe accidentally create a tag called master or anything like that?

Also git reflog should show what is going on.

like image 140
michas Avatar answered Sep 22 '22 11:09

michas