开发者

Checking out equivalent branches causes untracked files to appear

开发者 https://www.devze.com 2023-03-31 08:06 出处:网络
So I have 3 branches: master, testing, and dev. they all track respective branches on remotes/origin my git branch -a shows the following:

So I have 3 branches: master, testing, and dev. they all track respective branches on remotes/origin my git branch -a shows the following:

dev
master
testing
remotes/origin/master
remotes/origin/testing
remotes/origin/dev

When I release to testing I merge dev into testing then when I release the application I merge testing into master so master is effectively my release branch.

This has been working well for a while, I've had a few hiccups and had to do a few force pushes to origin. Not a big deal, small dev team a开发者_如何转开发nd all. Recently I made a release so all of my branches are currently equivalent (master == testing == dev == origin/master == origin/testing == origin/dev)

Today, another developer and I noticed that when we did a git checkout master a ton of untracked/moved/deleted/renamed files show up when running git status. This is weird, because remember all of the branches are pointing to the same commit. How can this happen?

The only way to fix it is to do something like git reset --hard origin/master then I can switch to testing or dev. Weird thing is this doesn't happen when switching between testing and dev, just when I switch to master

Trying to debug this, I did a fresh clone of origin into a new directory. The fresh checkout has the same problem as our checkouts. Any ideas?


More info, when I do the git checkout master it complains about abiguous ref 'master'

SOLUTION:

For some reason I had a ref named master in .git/refs/ It pointed to a REALLY old commit. so when I did git checkout master it complained about an ambiguous ref because there are two refs named master:

  1. The local tracking branch master which tracks origin/master
  2. This weird ref master I had hanging out at .git/refs/master

Hence the ambiguous refs complaint and the checkout command seemed to give the 2nd master preference. I deleted the file .git/refs/master and the issue went away.

I must have done something wrong during the clone, because I tried it again and it didn't give the extra master ref.

0

精彩评论

暂无评论...
验证码 换一张
取 消