How to `--assume-unchanged` file in project?

点点圈 提交于 2019-12-11 14:12:21

问题


I have config file: conf/local.conf I run next command for it:

git update-index --assume-unchanged local.conf

and it is OK until I switch to another branch or pull.

How to preserve --assume-unchanged flag between branches?

UPD
Some examples what is coming on:

$ git checkout 296-ToS-component 
error: Your local changes to the following files would be overwritten by checkout:
    conf/local.conf
Please commit your changes or stash them before you switch branches.
Aborting
$ git checkout -f 296-ToS-component 
error: Entry 'conf/local.conf' not uptodate. Cannot merge.

I want it works as next:

  1. conf/local.conf is saved
  2. Branch is switched
  3. conf/local.conf is replaced by saved version

回答1:


Don't use --assume-unchanged that should be used for performance problem for big files not changing and that are costly to hash when doing a git status.

What you want is --skip-worktree that do nearly the same things but to handle files that you changed but don't want to commit.

See https://stackoverflow.com/a/13631525/717372

And it will probably (not sure, but hey!, that's what you must do...) fix your problem...




回答2:


Remove the assume-unchanged bit:

git update-index --no-assume-unchanged local.conf

Save it:

git stash

Switch the branch:

git checkout 296-ToS-component

Retrieve the saved version:

git show stash@{0}:local.conf > local.conf

or merge the saved version with the current version:

git stash apply

and there might be conflicts which can be manually solved.

Set the assume-unchanged bit:

git update-index --assume-unchanged local.conf


来源:https://stackoverflow.com/questions/50639408/how-to-assume-unchanged-file-in-project

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