简体   繁体   English

如何忽略已经在git中跟踪的文件

[英]how to ignore files that are already tracked in git

I tried to pull origin a . 我试图pull origin a

and go the following: 然后执行以下操作:

error: Your local changes to the following files would be overwritten by merge:
    src/.cproject
    src/.project
    src/navigate/navigate_main.c
Please, commit your changes or stash them before you can merge.
Aborting

git status showed: git状态显示:

    modified:   .gitignore
modified:   src/.cproject
modified:   src/.project
modified:   src/navigate/navigate_main.c

I did git rm --cached src/.project to the first 3, and stashed the 4th 我做git rm --cached src/.project前3,并stashed第四

I did pull again and unstashed my changes. 我确实又拉了一下,却没有改动。

however when I do pull origin a 但是当我pull origin a

I get: 我得到:

M   .gitignore
U   src/.cproject
M   src/navigate/navigate_main.c
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.

how can I clean this once and for all? 我该如何彻底清洁呢?

Uncommitted changes are always bad. 未提交的更改总是不好的。 You have to decide whether those changes are good or bad. 您必须确定这些更改是好是坏。 If they are good, commit them. 如果它们很好,请提交它们。 If the are bad, discard them. 如果不好,请将其丢弃。

Once you have no more uncommitted changes you have no more problems. 一旦您不再有未提交的更改,就不会有任何问题。

Have a look at git status or git status --short to see any uncommitted changes. 查看git statusgit status --short可以查看任何未提交的更改。

Configure a meaningful prompt to see what is going on immediately. 配置有意义的提示以立即查看发生了什么。 For bash add something like this to your ~/.bashrc: 对于bash,在您的〜/ .bashrc中添加以下内容:

PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
GIT_PS1_SHOWDIRTYSTATE=yes
GIT_PS1_SHOWSTASHSTATE=yes
GIT_PS1_SHOWUNTRACKEDFILES=yes
GIT_PS1_SHOWUPSTREAM=auto

Your git rm --cached src/.project doesn't do much good unless you commit the change. 除非您commit更改,否则您的git rm --cached src/.project不会做得很好。 Why not just git stash everything, then pull , stash pop , and then remove the ignored files with rm --cached ? 为什么不仅仅使用git stash所有内容,然后使用rm --cached git stashpullstash pop ,然后删除被忽略的文件?

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

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