什么是实用的工作流,以保持本地更改不在git中提交? [英] What is a practical workflow for keeping local changes uncommitted in git?

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

问题描述

该问题已经在该问题中进行了描述.但是我想以一种实用且更通用的方式解决该问题.因此,用例如下:

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

此选项还可以用作粗略的文件级机制,用于 忽略跟踪文件中未提交的更改(类似于.gitignore 如果需要,Git将失败(正常) 修改索引中的此文件,例如合并提交时;因此, 如果假定未跟踪的文件在上游更改,则需要 手动处理情况.

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天全站免登陆