简体   繁体   中英

Git checkout untracked issue

I'm collaborating with a few other people on a Drupal website which we are version controlling Git. We setup a local Git repository containing our commits.

After a colleague pushed some updates and I fetched and merged into my local dev branch, I began experiencing the following problems:

user@server:/var/www/Intranet/sites/intranet/modules/custom$ git checkout dev 
error: The following untracked working tree files would be overwritten by checkout:
    themes/bigcompany/panels/layouts/radix_bryant_flipped/radix-bryant-flipped.png
    themes/bigcompany/panels/layouts/radix_bryant_flipped/radix-bryant-flipped.tpl.php
    themes/bigcompany/panels/layouts/radix_bryant_flipped/radix_bryant_flipped.inc
Please move or remove them before you can switch branches.
Aborting

The issue above typically shows up when I try to checkout into other branches which fails and I am effectively trapped in my current branch.

Referring to this question, there is a suggestion my issue is related to the gitignore file. However, my .gitignore file has nothing indicating any part of my themes directory should be ignored as the following shows:

# .gitignore for a standard Drupal 7 build based in the sites subdirectory.

# Drupal
files
settings.php
settings.*.php

# Sass.
.sass-cache

# Composer
vendor/

# Migrate sourec files
modules/custom/haringeygovuk_migrate/source_data

As mentioned above, my attempts to execute git checkout into any branch fails with the message above. I decided to force it with the -f switch and successfully switched into my target branch but I lost a couple of hundred lines of code - which I'd love to avoid going forward.

I work on a Linux-Ubuntu VirtualBox which my colleagues prefer working in a WAMP setup and use the Git Bash terminal emulator for executing the Git commands. Could the difference in environments be causing these serious issues?

How can I resolve this issue?

Well, the situation is rather simple. You, in your current branch, don't have certain files under the control of Git, but at the same time, you have those files in your working tree. The branch you're trying to switch to, has those files, so git would need to override files in the working tree to perform checkout.

To prevent possible data loss, Git stops the process of switching the branches and notifies you that you should either add those files under the control of Git in a separate commit in your current branch, and only then perform the switch, or simply remove those files from the git way.

Likely you have chosen the second way. Generally you should "force" any operation only if you really understand what you're doing.

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