Git - How to automatically ignore a file after a clone?

China☆狼群 提交于 2019-12-19 10:08:22

问题


I would know if there is a way to include a file in a repo, but that it is automatically ignored after the user cloned the repo..

It would be great for configuration files: once you clone the repo, you just edit it (and you don't have to remember to put it in .gitignore)


回答1:


One way is to run git update-index --assume-unchanged filename.txt

Another way is to commit template versions of the files, do your clone, copy the templates and have the copied files in your .gitignore.

Unfortunately both approaches require you to do something after cloning.




回答2:


There are several options:

Add the file to .gitignore file

This will ignore the file and any changes made to it.

--assume-unchaged

Raise the --assume-unchaged flag on this file so it will stop tracking changes on this file

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated.

Instead, this option sets/unsets the assume unchanged bit for the paths.

When the assume unchanged bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.



来源:https://stackoverflow.com/questions/36461882/git-how-to-automatically-ignore-a-file-after-a-clone

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!