在分支机构检出之间保留git --assume-unchanged文件

Jef*_*eff 36 git

我一直在使用git --assume-unchanged yacs/settings/development.py我的dev分支中忽略我的本地数据库配置文件.但是当我想切换分支(用于部署)时,我得到一个错误,我仍然有待更改:

% git checkout production
error: Your local changes to the following files would be overwritten by checkout:
    yacs/settings/development.py
Please, commit your changes or stash them before you can switch branches.
Aborting
Run Code Online (Sandbox Code Playgroud)

这很烦人.我知道如何解决这个问题的唯一方法就是隐藏它:

% git stash
% git checkout production
% git merge dev
% ./deploy.sh
% git checkout dev
% git stash pop
# On branch dev
# 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:   yacs/settings/development.py
#
Run Code Online (Sandbox Code Playgroud)

但现在又回到了指数中(呃)!这个工作流程有更好的替代方案吗?

[我不特别在意本地更改是否保留在本地(也就是说,如果它是生产分支就没关系),我只是不希望它被推送到远程存储库.

Von*_*onC 20

你可以尝试(git update-index手册页):

git update-index --skip-worktree -- path
Run Code Online (Sandbox Code Playgroud)

Skip-worktree位可以在一个(长)句子中定义:当读取条目时,如果它被标记为skip-worktree,那么Git假装其工作目录版本是最新的并且改为读取索引版本.

但是,如" git假设未更改vs跳过工作树 "中所述:

两种选择都有问题.--assume-unchanged每当索引被丢弃时重置自己(例如git reset),这样可能迟早会绊倒你.同样如此--skip-worktree.

  • 尝试了`--assume-unchanged`和`--skip-worktree`后,当我在设置此属性后尝试切换本地分支时,两者都继续抱怨对文件的未提交更改. (6认同)
  • @amoe和那个文件已经版本化了吗?如果将该文件添加到`your_repo\.git\info\exclude`怎么办? (4认同)