所以我在。gitignore文件中添加了一个文件夹。

一旦我输入git状态,它就会告诉我

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

然而,当我尝试改变分支时,我得到以下结果:

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

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

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

我如何让这个工作,所以我可以切换分支而不删除这些文件?

如果我做了更改,会影响那些文件吗?换句话说,如果我之后回到这个分支,在我最近一次提交之前,一切都是完美的吗?

我不想弄丢那些文件,我只是不想让他们被追踪到。


当前回答

这很容易解决,git说你在两个分支中有相同的文件,因此你必须从主分支中删除特定的文件,然后你将能够合并:

git merge "your branch"

我希望它对你有用,我刚刚解决了我的错误。 我的错误是:

error: The following untracked working tree files would be overwritten by merge:
        .vs/slnx.sqlite
Please move or remove them before you merge.
Aborting

现在起作用了! 在我的例子中。vs/slnx。sqlite是visual studio生成的,删除之前需要关闭它。

其他回答

只需删除文件或重命名它们。

如。

$ git pull
Enter passphrase for key '/c/Users/PC983/.ssh/id_rsa':
error: Your local changes to the following files would be overwritten by merge:
        ajax/productPrice.php
Please commit your changes or stash them before you merge.
error: The following untracked working tree files would be overwritten by merge:
        ajax/product.php
Please move or remove them before you merge.
Aborting
Updating a04cbe7a..6aa8ead5

我不得不重命名/删除ajax/product.php和ajax/ productprice .php。

别担心,少壮派会把他们拉回来的。我建议您重命名它们,而不是删除它们,因为您可能会失去一些更改。

如果这没有帮助,那么你必须删除整个分支并重新创建它,然后执行git pull origin remotebranch

这很容易解决,git说你在两个分支中有相同的文件,因此你必须从主分支中删除特定的文件,然后你将能够合并:

git merge "your branch"

我希望它对你有用,我刚刚解决了我的错误。 我的错误是:

error: The following untracked working tree files would be overwritten by merge:
        .vs/slnx.sqlite
Please move or remove them before you merge.
Aborting

现在起作用了! 在我的例子中。vs/slnx。sqlite是visual studio生成的,删除之前需要关闭它。

检查是否有文件夹名包含'/'或任何特殊符号,然后重命名该文件夹。 然后只需将存储库克隆到另一个位置。

如果你使用的是OS X系统,可能是因为某个文件的名称发生了某些字符的变化。尝试设置以下配置选项:

git config core.ignorecase true

在我的情况下,问题是由于文件名称从订阅更改。ts到Subscribe.ts。

所以我检查我的分支开发人员是否与我所在的当前分支同步。

(电流支路主)

Git合并开发 已经是最新的了 Git分支-d dev Git checkout -b dev