git - 在 git 中保持未提交本地更改的实用工作流程是什么?

标签 git version-control dvcs

我想做的事情已经在that question中描述过了。 .但我想以一种实用且更通用的方式解决该问题。所以用例如下:

  • 我在多个文件 web.configcreateDb.sql 或任何其他文件中进行了多项本地更改
  • 我不想提交这些文件,因为更改仅针对我的本地机器
  • 这些文件必须是受版本控制的,而且其中一些文件(尤其是 sql 脚本)经常发生更改,所以我想接收这些文件的更新
  • 确实想要提交所有其他文件
  • 我希望能够通过一条命令(使用 posh-git,因此欢迎使用 powershell)毫无摩擦地做到这一点

链接到的解决方案据说使用 git add -p 并且不实用,一直手动选择 block 很无聊或者也许有一个更方便的方法?

例如,以下其中一项可能有效:

  • 如果有能力在将我的工作副本中的文件添加到索引之前对其进行过滤,例如 git -add -A -EXCEPT web.config crateDb.sql。然后我可以将 git 别名映射到它,仅此而已。
  • 是否有取消应用存储的能力。我的意思是从工作副本中删除一个特定存储中包含的更改。所以我必须在每次提交之前执行类似 git stash -deapply 的操作,这也很好。

这个问题很普遍,很奇怪目前没有解决办法。例如。 TortoiseSVN 具有“提交时忽略”功能,Perforce 允许将这种类型的本地更改存储在单独的更改列表中并且从不提交。

最佳答案

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

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

来自 git 帮助:

--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 - 在 git 中保持未提交本地更改的实用工作流程是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10236112/

相关文章:

git - Hg-Git:如何同时推送到 Github 和 Bitbucket?

git - 比较 Bitbucket 和 Github 的优缺点

mercurial - 我可以克隆 Mercurial 存储库的一部分吗?

version-control - 分布式版本控制系统真的没有集中存储库吗?

git - VS 2017 中正在进行 rebase 操作

eclipse - 独立的 Aptana Git 插件

git commit 没有在 OSX 上使用 GPG 正确签名

java - Oracle 和 Subversion 的集成

git - 如何删除sourcetree上的远程分支?

visual-studio - 如何将 TFS 工作项链接到 TFS 变更集