在分支签出之间保留git --assume - 不变的文件 [英] Preserve git --assume-unchanged files between branch checkouts
问题描述
我一直使用 git --assume -shared yacs / settings / development.py
忽略我的本地数据库配置文件在我的dev分支中。但是,当我想切换分支(用于部署)时,出现一个错误,我仍然有待更改:
I've been using git --assume-unchanged yacs/settings/development.py
to ignore my local database configuration file in my dev branch. But when I want to switch branches (for deployments), I get an error that I still have changes pending:
% 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
这很烦人。我知道如何解决这个问题的唯一方法就是保存它:
Which is annoying. The only way I know how to get around this would be to stash it:
% 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
#
但现在又回到了指数(唉)!有没有更好的替代这个工作流程?
But now it's back in the index again (ugh)! Is there a better alternative to this workflow?
[我不是特别在意本地更改是否保留在本地(也可以,如果它是生产分支),我只是不希望它被推送到远程存储库。]
[I don't particularly care if the local changes stay locally (aka, it's ok if it's the production branch), I just don't want it pushed to a remote repository.]
推荐答案
您可以尝试( git update-index手册页):
You can try (git update-index man page):
git update-index --skip-worktree -- path
Skip-worktree位可以在一个(长)句子中定义:当读入一个条目时,如果它被标记为skip-worktree,那么Git假装它的工作目录版本是最新的并且读取索引版本。
Skip-worktree bit can be defined in one (long) sentence: When reading an entry, if it is marked as skip-worktree, then Git pretends its working directory version is up to date and read the index version instead.
然而,正如 git假设不变或跳过worktree :
两个选项都有问题。
- 假设 - 不变
在索引被丢弃时重置自身(例如git reset
),这样可能会让你迟早会发生。同样适用于- skip-worktree
。
Both options have problems.
--assume-unchanged
resets itself whenever the index gets discarded (e.g.git reset
), so that will probably trip you up sooner or later. Same goes for--skip-worktree
.
这篇关于在分支签出之间保留git --assume - 不变的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!