简体   繁体   English

Git Checkout未跟踪问题

[英]Git checkout untracked issue

I'm collaborating with a few other people on a Drupal website which we are version controlling Git. 我正在Drupal网站上与其他一些人合作,我们正在控制Git的版本。 We setup a local Git repository containing our commits. 我们设置了一个包含提交的本地Git存储库。

After a colleague pushed some updates and I fetched and merged into my local dev branch, I began experiencing the following problems: 同事推送了一些更新后,我获取并合并到本地dev分支中,我开始遇到以下问题:

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. 关于这个问题,有一个建议是我的问题与gitignore文件有关。 However, my .gitignore file has nothing indicating any part of my themes directory should be ignored as the following shows: 但是,我的.gitignore文件没有任何内容,表明应忽略主题目录的任何部分,如下所示:

# .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. 如上所述,我尝试将git checkout执行到任何分支的尝试均因上述消息而失败。 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. 我决定使用-f开关强制执行此操作,并成功切换到我的目标分支,但是我丢失了几百行代码-我希望避免继续。

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. 我在Linux-Ubuntu VirtualBox上工作,我的同事们更喜欢在WAMP设置中工作,并使用Gi​​t Bash终端仿真器执行Git命令。 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. 您在当前分支中没有某些文件在Git的控制下,但同时,您的工作树中也有这些文件。 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. 您要切换到的分支具有这些文件,因此git需要覆盖工作树中的文件以执行检出。

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. 为了防止可能的数据丢失,Git停止了分支的切换过程,并通知您您应该在当前分支的单独提交中在Git的控制下添加这些文件,然后再执行切换,或者只是删除这些文件从git的方式。

Likely you have chosen the second way. 您可能选择了第二种方式。 Generally you should "force" any operation only if you really understand what you're doing. 通常,只有真正了解自己在做什么时,才应“强制”执行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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