以下未跟踪的工作树文件将被checkout覆盖 [英] The following untracked working tree files would be overwritten by checkout

查看:145
本文介绍了以下未跟踪的工作树文件将被checkout覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



一旦我做了一个 git status ,它会告诉我分支最新的
没有提交(工作目录干净)
$ b

  c> 

但是,当我尝试更改分支时,我得到以下内容:

  My-MacBook-Pro:webapp marcamillion $ git checkout开发
错误:以下未跟踪的工作树文件将被checkout覆盖:
public / system / images / 9 / thumb /red-stripe.jpg
public / system / images / 9 / original / red-stripe.jpg
public / system / images / 8 / thumb / red-stripe-red.jpg
public / system / images / 8 / original / red-stripe-red.jpg
public / system / images / 8 / original / 00-louis_c.k.-chewed_up-cover-2008.jpg
public /system/images/7/thumb/red-stripe-dark.jpg
public / system / images / 7 / original / red-stripe-dark.jpg
public / system / images / 7 / original /DSC07833.JPG
public / system / images / 6 / thumb / red-strip e-bw.jpg
public / system / images / 6 / original / website-logo.png
public / system / images / 6 / original / red-stripe-bw.jpg
public /system/images/5/thumb/Guy_Waving_Jamaican_Flag.jpg
public / system / images / 5 / original / logocompv-co​​lored-squares-100px.png
public / system / images / 5 / original / Guy_Waving_Jamaican_Flag .jpg
public / system / images / 4 / thumb / DSC_0001.JPG
public / system / images / 4 / original / logo.png
public / system / images / 4 / original / DSC_0001.JPG
public / system / images / 4 / original / 2-up.jpg
public / system / images / 3 / thumb / logo2.gif
public / system / images / 3 /original/logo2.gif
public / system / images / 3 / original / Guy_Waving_Jamaican_Flag.jpg
public / system / images / 3 / original / 11002000962.jpg
public / system / images / 2 / thumb / Profile Pic.jpg
public / system / images / 2 / original / Profile Pic.jpg
public / system / images / 2 / original / 02登录Screen.jpg
public /系统/图片/ 1 /原厂/阿根廷-2010-W orld-Cup.jpg
请在移动或删除它们,然后才能切换分支。
正在取消

这就是我的.gitignore文件的样子:

  .bundle 
.DS_Store
db / *。sqlite3
log / *。log
tmp / ** / *
public / system / images / *
public / system / avatars / *

我如何得到这个工作,所以我可以在不删除这些文件的情况下切换分支?



如果我进行了更改,是否会影响这些文件?换句话说,如果我以后再回到这个分支,那么一切都会完美无缺,就像我最近的提交一样?



我不想丢失这些文件,我只是不希望它们被跟踪。

解决方案

好像你想忽略这些文件,但它们已经被提交。 .gitignore对已存在于回购库中的文件没有影响,因此需要使用 git rm --cached 删除它们。 --cached 会阻止它对您的工作副本产生任何影响,并且只会在您下次提交时将其标记为已删除。文件从回购库中删除后,那么.gitignore将阻止它们再次被添加。



但是你的.gitignore存在另一个问题,你过度使用通配符并导致它比你期望的要少。

  .bundle 
.DS_Store
db / *。改变.gitignore并试试。 sqlite3 $ b $ log / * .log
tmp /
public / system / images /
public / system / avatars /


So I added a folder to my .gitignore file.

Once I do a git status it tells me

# On branch latest
nothing to commit (working directory clean)

However, when I try to change branches I get the following:

My-MacBook-Pro:webapp marcamillion$ git checkout develop
error: The following untracked working tree files would be overwritten by checkout:
    public/system/images/9/thumb/red-stripe.jpg
    public/system/images/9/original/red-stripe.jpg
    public/system/images/8/thumb/red-stripe-red.jpg
    public/system/images/8/original/red-stripe-red.jpg
    public/system/images/8/original/00-louis_c.k.-chewed_up-cover-2008.jpg
    public/system/images/7/thumb/red-stripe-dark.jpg
    public/system/images/7/original/red-stripe-dark.jpg
    public/system/images/7/original/DSC07833.JPG
    public/system/images/6/thumb/red-stripe-bw.jpg
    public/system/images/6/original/website-logo.png
    public/system/images/6/original/red-stripe-bw.jpg
    public/system/images/5/thumb/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/5/original/logocompv-colored-squares-100px.png
    public/system/images/5/original/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/4/thumb/DSC_0001.JPG
    public/system/images/4/original/logo.png
    public/system/images/4/original/DSC_0001.JPG
    public/system/images/4/original/2-up.jpg
    public/system/images/3/thumb/logo2.gif
    public/system/images/3/original/logo2.gif
    public/system/images/3/original/Guy_Waving_Jamaican_Flag.jpg
    public/system/images/3/original/11002000962.jpg
    public/system/images/2/thumb/Profile Pic.jpg
    public/system/images/2/original/Profile Pic.jpg
    public/system/images/2/original/02 Login Screen.jpg
    public/system/images/1/original/Argentina-2010-World-Cup.jpg
Please move or remove them before you can switch branches.
Aborting

This is what my .gitignore file looks like:

.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/**/*
public/system/images/*
public/system/avatars/*

How do I get this working so I can switch branches without deleting those files?

If I make a change, will it affect those files? In other words, if I came back to this branch afterwards would everything be perfect as up to my latest commit?

I don't want to lose those files, I just don't want them tracked.

解决方案

It seems like you want the files ignored but they have already been commited. .gitignore has no effect on files that are already in the repo so they need to be removed with git rm --cached. The --cached will prevent it from having any effect on your working copy and it will just mark as removed the next time you commit. After the files are removed from the repo then the .gitignore will prevent them from being added again.

But you have another problem with your .gitignore, you are excessively using wildcards and its causing it to match less than you expect it to. Instead lets change the .gitignore and try this.

.bundle
.DS_Store
db/*.sqlite3
log/*.log
tmp/
public/system/images/
public/system/avatars/

这篇关于以下未跟踪的工作树文件将被checkout覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆