什么是保持本地变更在git中无法实现的实用工作流程? [英] What is a practical workflow for keeping local changes uncommited in git?

查看:109
本文介绍了什么是保持本地变更在git中无法实现的实用工作流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要做的是在该问题中描述。但我想以一种实用且更通用的方式解决这个问题。因此,用例如下:


  • 我在几个文件 web.config中有几个本地修改 code>, createDb.sql 或其他任何其他

  • 我不想提交这些文件,因为更改是仅限于本地机器

  • 这些文件必须受版本控制,而且其中一些文件(特别是sql脚本)经常发生更改,所以我希望接收这些文件的更新

  • 要提交所有其他文件

  • 我希望能够在一个命令中做到这一点(使用posh-git,所以powershell是受欢迎的)



据说使用的链接解决方案 git add -p ,那是不实用,所以无时无刻都要手动挑选块,或者有一种更方便的做法例如,以下其中一项可能有效:




    i>是否有能力筛选我的工作副本中的文件,然后将它们添加到索引中,如 git -add -A -EXCEPT web.config crateDb.sql 。然后,我可以将git别名映射到那个,就是这样。如果有能力取消存储,

  • 。我的意思是从工作副本中删除包含在特定存储中的更改。因此,我必须在每次提交之前执行 git stash -deapply 之类的操作。



这个问题很常见,目前没有解决方案,这很奇怪。例如。 TortoiseSVN具有忽略提交功能,Perforce允许将该类型的本地更改存储在单独的更改列表中,并且永不提交它...



有什么想法? / p>

解决方案

您可以在git commit之前尝试执行以下操作:

  git update-index --assume-unchanged web.config crateDb.sql 

来自git help:


- 承担 - 不变
$ b

- 无假设不变

当指定这些标志时,记录
路径不会更新。相反,这些选项设置和
取消路径的假定不变位。当假设
不变位时,git停止检查工作树文件中的
可能的修改,因此当您更改工作树时需要手动取消该位以告知
git文件。在一个非常缓慢的
lstat(2)系统调用(例如cifs)的文件系统上处理一个大项目时,这有时是有用的


这个选项也可以用作一个粗略的文件级机制,以
忽略跟踪文件中的未提交更改(类似于.gitignore
为未跟踪文件所做的操作)。
如果它需要
在索引中修改这个文件,就会失败(优雅地)合并时提交;因此,如果假设未跟踪文件在上游发生更改,
将需要
手动处理。



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:

  • 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)

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:

  • 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.

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...

Any thoughts?

解决方案

You could try doing the following before your git commit:

git update-index --assume-unchanged web.config crateDb.sql

From git help:

--assume-unchanged

--no-assume-unchanged

When these flags are specified, the object names recorded for the paths are not updated. Instead, these options set and unset the "assume unchanged" bit for the paths. When the "assume unchanged" bit is on, git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell git when you change the working tree file. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). Git will fail (gracefully) in case it needs to 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 need to handle the situation manually.

这篇关于什么是保持本地变更在git中无法实现的实用工作流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆