简体   繁体   English

无法“取消跟踪”文件(忽略对跟踪文件的进一步更改)

[英]Having trouble “untracking” file (ignore further changes to tracked file)

I have an issue on git. 我对git有问题。 Recently I made a mistake and added a directory to my repo by using git add -f path/to/folder. 最近我犯了一个错误,并使用git add -f path / to / folder将目录添加到了我的仓库中。 Now I'm trying really hard to ignore this folder but nothing works. 现在,我非常努力地忽略此文件夹,但是没有任何效果。 So far I did : 到目前为止,我做到了:

git update-index --assume-unchanged path/to/folder

The command above did the job but once I give the right to this folder using chmod -R 777 the change appear again in git status : 上面的命令完成了这项工作,但是一旦我使用chmod -R 777将此文件夹授予权限,更改将再次以git status出现:

# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   app/tmp/cache/models/myapp_cake_model_default_contractsign_attachments
#   modified:   app/tmp/cache/models/myapp_cake_model_default_contractsign_list
#   modified:   app/tmp/cache/models/myapp_cake_model_default_contractsign_signatures
#   modified:   app/tmp/cache/models/myapp_cake_model_default_contractsign_users
#   modified:   app/tmp/cache/persistent/myapp_cake_core_cake_dev_eng
#   modified:   app/tmp/cache/persistent/myapp_cake_core_cake_dev_fre
#   modified:   app/tmp/cache/persistent/myapp_cake_core_cake_dev_spa
#   modified:   app/tmp/cache/persistent/myapp_cake_core_cake_eng
#   modified:   app/tmp/cache/persistent/myapp_cake_core_cake_fre
#   modified:   app/tmp/cache/persistent/myapp_cake_core_cake_spa
#   modified:   app/tmp/cache/persistent/myapp_cake_core_default_eng
#   modified:   app/tmp/cache/persistent/myapp_cake_core_default_fre
#   modified:   app/tmp/cache/persistent/myapp_cake_core_default_spa
#   modified:   app/tmp/cache/persistent/myapp_cake_core_file_map
#   modified:   app/tmp/cache/persistent/myapp_cake_core_method_cache
#   modified:   app/tmp/logs/error.log
#
no changes added to commit (use "git add" and/or "git commit -a")

EDIT: Maybe I was a bit unclear before. 编辑:也许我之前还不清楚。 So basically for my project, I want the current contents of them tmp/ folder added, but changes no longer be tracked by git. 因此,基本上对于我的项目,我希望添加其中的当前内容tmp/文件夹,但是git不再跟踪更改。 So I did this: 所以我这样做:

$ git update-index --assume-unchanged app/tmp/
Ignoring path app/tmp/

But now, in order to make my application work again, I need to give write permission for files in folder, so I did: 但是现在,为了使我的应用程序再次运行,我需要为文件夹中的文件提供写权限,所以我做了:

sudo chmod -R 777 app/tmp/

But once I did that, I got the log you can see above under Changes not staged for commit: . 但是一旦这样做,我就可以在上面的日志中看到未更改提交的更改: I don't want those changes tracked, just ignored. 我不想跟踪那些更改,只是忽略了。

Just for information, here is what I have in my gitignore : 仅供参考,这是我在gitignore中拥有的内容:

/app/tmp/*

You appear to have mixed together different things because you don't know what they do. 您似乎混合了不同的事物,因为您不知道它们的作用。

Marking a file as "assume-unchanged" will ignore further changes to a tracked file -- this is not what you say you want. 将文件标记为“假定不变”将忽略对跟踪文件的进一步更改-这不是您想要的。 (Note: The question was originally saying the OP wants to untrack the files) (注意:问题本来是说OP想要取消跟踪文件)

Using git rm --cached only removes a file from the index (staging area), but does not tell Git anything about ignoring it from now on, so you were on the right track, but you didn't go all the way. 使用git rm --cached只会从索引(临时区域)中删除文件,但是从现在开始不会告诉Git关于忽略该文件的任何信息,因此您处在正确的轨道上,但并没有完全成功。

After removing the file (it is now untracked again, but Git always tells you about untracked content), you have to additionally add an entry for it to one of your ignore files in Git; 删除文件后(现在再次取消跟踪,但是Git总是告诉您未跟踪的内容),您还必须为此添加一个条目到Git中的一个忽略文件中; then it will not show it again in the status message. 则它不会在状态消息中再次显示。

To do this, append this entry to the file .gitignore in your repo's root (create that file if it doesn't exist yet): 为此,请将此条目附加到存储库根目录中的.gitignore文件中(如果尚不存在,则创建该文件):

/full/path/to/my_file_name

Of course, don't use that literally but use the actual path instead. 当然,不要直接使用它,而应使用实际路径。 Note that the leading slash does not mean "file system root" but "repo's root" in this case. 请注意,在这种情况下,前导斜线并不表示“文件系统根”,而是“存储库的根”。


Edit: After you have provided more information, your problem is clearer. 编辑:提供更多信息后,您的问题更加清楚。 You do not actually want to untrack some files (ie remove them from version control), but only ignore further changes to them. 您实际上并不想取消跟踪某些文件(即从版本控制中将其删除),而只忽略对它们的进一步更改。

For this, "assume-unchanged" is indeed the right way of going at it, but assume-unchanged does not work recursively on directories . 为此,“假定​​不变”确实是正确的处理方法,但是假定不变在目录上不能递归工作 That means that you will have to set it explicitly on every file whose changes you want to overlook. 这意味着您将必须在要忽略其更改的每个文件上进行显式设置。 You can do this in a single command: 您可以在一个命令中执行此操作:

git update-index --assume-unchanged -- file1 file2 file3 ...

If there were a great many files, this could be scripted, but since you only seem to have about 15 files, it would take longer to make the script (files are in different directories) than for you to just copy-paste the paths into a command. 如果有很多文件,可以编写脚本,但是由于您似乎只有大约15个文件,因此制作脚本(文件位于不同目录中)所花费的时间要比仅将路径复制粘贴到其中要长。命令。

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

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