问题描述
该问题已经在该问题中进行了描述.但是我想以一种实用且更通用的方式解决该问题.因此,用例如下:
What I want to do is already described in that question. But I want to solve that problem in a practical and more generic way. So the use-case is the following:
- 我在几个文件
web.config
,createDb.sql
或其他任何文件中都进行了一些本地更改 - 我不想提交这些文件,因为更改仅针对我的本地计算机
- 这些文件必须受版本控制,而且其中一些文件(尤其是sql脚本)经常进行更改,所以我想接收这些文件的更新
- 我要做要提交所有其他文件
- 我希望能够在一个命令中做到这一点(使用posh-git,因此欢迎使用powershell)
- I have several local changes in several files
web.config
,createDb.sql
or in any others - I don't want to commit those files, since changes are specific to my local machine only
- Those files must be version controlled and moreover changes are made pretty often to some of them (sql scripts in particular), so I want to receive updates for those files
- I do want to commit all other files
- I want to be able to do that without friction, in one command (using posh-git, so powershell is welcome)
据说使用git add -p
的链接到的解决方案,不实际,无聊地一直手动选择大块的东西,或者也许有更方便的方法?
The linked-to solution said to use git add -p
and that is not practical, it is boring to pick chunks manually all the time or maybe there is a more convenient way of doing that?
例如,以下其中一项可能有效:
For instance, one of the following could work:
- 如果能够在将我的工作副本中的文件添加到索引之前对其进行过滤,例如
git -add -A -EXCEPT web.config crateDb.sql
.然后,我可以将git别名映射到该别名. - 是否具有取消隐藏的功能.我的意思是从工作副本中删除一个特定存储中包含的更改.因此,在每次提交之前,我都必须执行
git stash -deapply
之类的事情.
- if there is an ability to filter files that are in my working copy before adding them to index, something like
git -add -A -EXCEPT web.config crateDb.sql
. Then I can map a git alias to that and that's it. - if there is an ability to de-apply stash. I mean to remove changes that is contained in one specific stash from the working copy. So I will have to do something like
git stash -deapply
before each commit that is also fine.
这个问题很常见,很奇怪,目前没有解决方案.例如. TortoiseSVN具有提交时忽略"功能,Perforce允许将该类型的本地更改存储在单独的更改列表中,而从不提交.
The problem is very common and it is weird that there is no solution currently. E.g. TortoiseSVN has "ignore-on-commit" feature, Perforce allows to store that type of local changes in a separate changelist and never submit it.
推荐答案
您可以在git commit之前尝试执行以下操作:
You could try doing the following before your git commit:
git update-index --assume-unchanged web.config crateDb.sql
在git帮助中:
-无假设不变
指定这些标志时,为路径未更新.相反,这些选项设置和取消设置假定不变".路径的位.当假设不变"位打开,git停止检查工作树文件是否存在可能的修改,因此您需要手动取消设置该位以告知更改工作树文件时的git.有时这很有帮助在非常慢的文件系统上处理大型项目时lstat(2)系统调用(例如CIF).
When these flags are specified, the object names recorded for thepaths are not updated. Instead, these options set andunset the "assume unchanged" bit for the paths. When the "assumeunchanged" bit is on, git stops checking the working tree files forpossible modifications, so you need to manually unset the bit to tellgit when you change the working tree file. This is sometimes helpfulwhen working with a big project on a filesystem that has very slowlstat(2) system call (e.g. cifs).
此选项还可以用作粗略的文件级机制,用于忽略跟踪文件中未提交的更改(类似于.gitignore如果需要,Git将失败(正常)修改索引中的此文件,例如合并提交时;因此,如果假定未跟踪的文件在上游更改,则需要手动处理情况.
This option can be also used as a coarse file-level mechanism toignore uncommitted changes in tracked files (akin to what .gitignoredoes for untracked files). Git will fail (gracefully) in case it needsto 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 needto handle the situation manually.
这篇关于什么是实用的工作流,以保持本地更改不在git中提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!