desktop / desktop

Focus on what matters instead of fighting with Git.
https://desktop.github.com
MIT License
19.86k stars 9.45k forks source link

can't cleanly checkout branch where tag exists with same name #7726

Open slx7R4GDZM opened 5 years ago

slx7R4GDZM commented 5 years ago

Description

Ever since GitHub Desktop updated to version 2.0 I can't push commits to GitHub on one of my repositories.

Version

Additional Information

It's also saying detached head in the branch name instead of master like it used to. Here's some screenshots. GitHub 1 GitHub 2

Logs

The logs don't say anything relevant, just that it found my repositories and my account.

iAmWillShepherd commented 5 years ago

@slx7R4GDZM

Does signing out and signing back in solve the problem?

Screen Shot 2019-06-07 at 12 20 22 PM

slx7R4GDZM commented 5 years ago

@iAmWillShepherd Nope, same thing except that I went back one commit. GitHub I'm going to sleep for now.

say25 commented 5 years ago

@slx7R4GDZM does the repo fall under "GitHub" or "Other" in the repo list?

billygriffin commented 5 years ago

For additional context @slx7R4GDZM, we're trying to correlate this issue with #7713 to figure out whether it might be a similar problem - thanks for being patient with us and sorry you're experiencing this! I'm also definitely interested in the answer to @say25's question above, in addition to whether there's anything unique in your repos about this particular repo where you're experiencing the problem.

steveward commented 5 years ago

@slx7R4GDZM it would also be helpful if you could still upload the log files -- sometimes there can be information that could give us some insight into what's happening.

slx7R4GDZM commented 5 years ago

@say25 How can you tell? Is it just from the hover text? If so that does have the right repo URL.

@steveward Here's my log.

say25 commented 5 years ago

@slx7R4GDZM if you click on Sine in the upper left, you should get a menu similar to this: 343B5345-827B-49BD-B147-BDAE755683F7

slx7R4GDZM commented 5 years ago

@say25 Untitled

shiftkey commented 5 years ago

@slx7R4GDZM you won't be able to push while you're on a detached HEAD scenario, and that's unrelated to what accounts you have. Are you able to switch to one of these branches in the list?

Seeing heads/ listed there makes me a bit nervous that something is weird with the repository setup, but for the moment I believe this is a separate problem to #7713.

@slx7R4GDZM what happens when you run git checkout master on the command line? Can you share the output here?

EDIT: also, could you run and include the output of this command? I think the heads/ prefix here is a flag that there are multiple refs named master and HolyC here, and I think figuring out what those are will let us get you back to a good place:

$ git for-each-ref
slx7R4GDZM commented 5 years ago

@shiftkey

Are you able to switch to one of these branches in the list?

I can switch between the branches, they both show up as a detached head though.

what happens when you run git checkout master on the command line?

User@User-PC MINGW64 ~/Documents/GitHub/Sine ((master))
$ git checkout master
warning: refname 'master' is ambiguous.
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

User@User-PC MINGW64 ~/Documents/GitHub/Sine (master)
$

also, could you run and include the output of this command?

User@User-PC MINGW64 ~/Documents/GitHub/Sine ((HolyC))
$ git for-each-ref
8155680144968b52f033d087ca8a263db1f45d39 commit refs/heads/HolyC
2e8e78b11cb4d1acd96a92032d247630a9cf1786 commit refs/heads/master
2e8e78b11cb4d1acd96a92032d247630a9cf1786 commit refs/remotes/origin/HEAD
8155680144968b52f033d087ca8a263db1f45d39 commit refs/remotes/origin/HolyC
2e8e78b11cb4d1acd96a92032d247630a9cf1786 commit refs/remotes/origin/master
1da14ad4c4007c6003794a46210f4ff0d728c2d7 commit refs/tags/2016-10-30
6bd81c7ab9f5f47d360989c58f401b9dd47bf65d commit refs/tags/2016-12-26
4cf918aba14c345468511678961a479a650491bc commit refs/tags/2017-03-26
ad1a18d6c2d88547384723ba1346e8e020f2da3d commit refs/tags/2017-10-24
1129dde431ee65eb8f178c87b412ecc1e7d02287 commit refs/tags/2017-11-04
8155680144968b52f033d087ca8a263db1f45d39 commit refs/tags/HolyC
8155680144968b52f033d087ca8a263db1f45d39 commit refs/tags/HolyC-r14
182ca8833b43b4c32b5722015516d8d590269a99 commit refs/tags/HolyC-revision-4
09379fbcc47c2b54469336bd5fb3799a3505b19c commit refs/tags/HolyC-revision-6
7120167364e8c77d2602633e13607ae304d4cd54 commit refs/tags/HolyC-revision-7
2e8e78b11cb4d1acd96a92032d247630a9cf1786 commit refs/tags/master
2e8e78b11cb4d1acd96a92032d247630a9cf1786 commit refs/tags/master-r65

Oh wow, lots of old tags.

shiftkey commented 5 years ago

@slx7R4GDZM excellent, it looks like there are some clashes here between tags and branches.

I'm not sure how much you rely on the tags, but because you have a tag that matches the name of a branch, in this case master and HolyC, it looks like checkout is not working as expected.

I can switch between the branches, they both show up as a detached head though.

Now that I know about the tags, I can reproduce this issue on my end. Investigating the fix now.

shiftkey commented 5 years ago

Tentatively marking this as priority-3 because it's only been reported by one user, but the impact to workflows is pretty serious (unable to checkout a branch, unable to push changes) that I think it's close to being a priority-2.

shiftkey commented 5 years ago

The root cause of this problem is doing a checkout when both a branch and tag exist with the same name. Even though the app correctly passes in heads/master to distinguish from the existing tag, Git still puts the repository in the detached HEAD state:

$ git -c credential.helper= checkout --progress heads/master --recurse-submodules -- 
Note: checking out 'heads/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

This behaviour is reproducible on Git 2.22, but given we're being as unambiguous here as possible I wonder if this is a legit Git bug...

shiftkey commented 5 years ago

@slx7R4GDZM if you can live without tags that use the exact same name as your branches, you can workaround this issue by deleting those like this from the command line:

$ git tag -d [name]

You'll then see your branches list update to omit the heads/ part of each branch name, and your checkout will then work again as expected.

slx7R4GDZM commented 5 years ago

@shiftkey

if you can live without tags that use the exact same name as your branches, you can workaround this issue by deleting those like this from the command line:

Awesome, it's not showing detached head anymore. I didn't even know those tags still existed after I removed them on the GitHub web interface.

shiftkey commented 5 years ago

@slx7R4GDZM thanks for confirming the workaround!

I didn't even know those tags still existed after I removed them on the GitHub web interface.

Tags will still exist in your local repository because it's separate from the remote repository, and aren't propagated like other changes to refs.

TheDoubleH commented 5 years ago

Just as a FYI - I have the same issue - Using VS Code

tidy-dev commented 2 months ago

Still able to reproduce as of GitHub Desktop 3.4.5 and Git 2.43.4. Just echoing, this behavior is the the same on command line so it is not a GitHub Desktop bug. That said, we could potentially see if this is a bug in Git and, if not, detect this state and inform the user.