简体   繁体   中英

IntelliJ Git Integration plugin: ^0 appended to branch name when checkout is attempted

I use the IntelliJ Git Integration plugin. I operate in multiple-repository mode and normally things work fine.

When I tell Git to check out a branch name by typing it instead of picking it from the multi-repo/branch UI, it's appending ^0 to the branch name resulting in a console message that I am checking out in Detached Head state. I am more familiar with what 'detached head' means than with the caret "^" syntax so I'm not 100% sure how accurate the message is.

Nonetheless, Does anyone know why this is happening? Why has it chosen to checkout mybranch^0 instead of just mybranch?

(From Git UI in lower right, select repo, choose 'Checkout tag or revision', type branch name instead of selecting it from the UI list of branches)

"Console" display in IntelliJ:

09:50:54.244: [reponame] git -c core.quotepath=false -c log.showSignature=false checkout feature/ branchName^0 --

Git bash shows detached head state rather than being on the branch:

user@WORKSTATION MINGW64 /c/dev/intellij projects/repo-name ((b72ad203...))

In Git, checking out a tag or commit hash directly always puts you into "detached HEAD" state. To make the behaviour of "checkout tag or revision" consistent, the Git plugin is deliberately adding the ^0 so that you check out the most recent commit on the branch you selected, in "detached HEAD" state, just as if you'd typed the hash of that commit directly. That is, it's doing this so that "checkout tag or revision" always puts you in "detached HEAD" state.

If it didn't do this, it would be much harder to achieve this effect: you'd have to look in the log to find which commit is the latest on that branch, then copy-paste the commit hash into the "checkout revision" pop-up.

If that's not what you want, don't use "checkout tag or revision". Instead just pick the branch from the branch UI. Don't forget that in IntelliJ, every list and menu has type-ahead filtering, so you can type some letters from the branch name to avoid having to read the whole list.

What is this ^ thing anyway?

The ^ notation in Git selects parent commits. commit^ or commit^1 means the first parent, commit^2 means the second parent (ie of a merge), and so on. ^0 means the same commit. commit can be any way of naming a commit, including the hash or a branch name.

Because you can use a branch name, branch^0 means the latest commit on branch , but it names the commit itself, not the branch. Because it specifies a particular commit, not a branch, it goes into "detached HEAD" state.

There is no action to checkout a branch by typing in IntelliJ. There is action called Checkout Tag or Revision, it is intended to checkout to detached state. See the Dan's answer, and https://youtrack.jetbrains.com/issue/IDEA-181686

To checkout a branch in IntelliJ, use the Checkout action from the corresponding branch's action list. Branches popup supports speedsearch, so you could do that without a mouse:

  1. Open branches popup with a shortcut - Ctrl+Shift+[Backquote] on Win, check in Keymap
  2. Type the branch name
  3. Enter to open actions list
  4. Select action and Enter to execute

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM