How to properly handle a file only used locally in git?

允我心安 提交于 2021-02-08 04:07:33

问题


I want to reorder the output of changed files in git commits so I've created a file called submodule/orderfile and configured diff.orderFile to point to that file.

Now many problems arise

  • If I add the file to .gitignore, the .gitignore will be listed as modified
  • If I add the path submodule/orderfile to .git/info/exclude the file still appears when I run git status.

Either way, orderfile or .gitignore will be listed in git status. If I commit it to a branch it'll be removed when I switch to another branch. I don't want to push those files because I only use them locally.

I tried to run git update-index --assume-unchanged orderfile like stated here but it gives

fatal: Unable to mark file orderfile

More importantly even if I can manage to ignore the file, it'll be removed when I run git clean -xdf

So how can I told git to not track the file and still leave it as-is when I run git clean -xdf?


回答1:


How about moving the file out of the repository and configuring diff.orderFile to the new path?

That was my first thought, but diff.orderFile is a relative pathname, it is treated as relative to the top of the working tree.
Maybe ../afile would work.

An alternative is to define a git wrapper script which calls git, but with the -O option when using diff.
That way, you can really place the orderfile outside the repo.



来源:https://stackoverflow.com/questions/44104238/how-to-properly-handle-a-file-only-used-locally-in-git

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