svn - 使用 Git 处理颠覆 : Ignoring modifications to tracked files

标签 svn git git-svn gitignore

我目前正在使用一个 subversion 存储库,但我正在使用 git 在我的机器上本地工作。它使工作变得更容易,但它也使 subversion 存储库中发生的一些不良行为非常明显,这给我带来了问题。

在下 pull 代码后有一个有点复杂的本地构建过程,它创建(不幸的是修改)了许多文件。显然,这些更改并不意味着要提交回存储库。不幸的是,构建过程实际上是在修改一些跟踪文件(是的,很可能是因为有人在某个时候错误地将这些构建工件提交到颠覆存储库)。由于这些是修改,将它们添加到我的忽略文件对我没有任何作用。

我可以避免检查这些更改,我只是不暂存或提交它们,但是未暂存的本地更改意味着我不能在不先清理它们的情况下 rebase 。

我想知道的是,是否有任何方法可以忽略对一组跟踪文件的 future 更改?或者,是否有另一种方法来处理我遇到的问题,或者我是否只需要告诉 checkin 这些文件的人清理它们?

最佳答案

作为Nathan said ,清理这些文件(取消跟踪)是明智之举。

但是如果你必须忽略跟踪的文件(这不是忽略文件的 native Git 方式:Git 只忽略非跟踪 文件),你可以设置一个进程来复制文件的内容您想要忽略的文件,并在提交时恢复。

我最初认为 smudge/clean process , 那是一个 gitattributes filter driver可以做到这一点:

alt text

,其中:

  • 涂抹过程将复制这些文件(更新工作树时)
  • 在构建过程中进行了一些修改
  • 清除步骤(在提交期间)将使用步骤 1 中制作的副本删除文件内容。

但是,作为 stated in this post ,这意味着通过添加有状态的上下文(即被污染/清理的文件的完整路径名)来滥用此无状态文件内容转换。
这是 J.C. Hamano 明确禁止的:

Although I initially considered interpolating "%P" with pathname, I ended up deciding against it, to discourage people from abusing the filter for stateful conversion that changes the results depending on time, pathname, commit, branch and stuff.

甚至Linus Torvalds had some reservations当时关于all机制:

I have to say, I'm obviously not a huge fan of playing games, but the diffs are very clean.

Are they actually useful? I dunno. I'm a bit nervous about what this means for any actual user of the feature, but I have to admit to being charmed by a clean implementation.

I suspect that this gets some complaining off our back, but I also suspect that people will actually end up really screwing themselves with something like this and then blaming us and causing a huge pain down the line when we've supported this and people want "extended semantics" that are no longer clean.

But I'm not sure how valid an argument that really is. I do happen to believe in the "give them rope" philosophy. I think you can probably screw yourself royally with this, but hey, anybody who does that only has himself to blame


因此添加某种保存/恢复机制(并有效地忽略对 Git 中的一组跟踪文件的任何更改)的正确位置将在 hooks:

  • post-checkout:在更新工作树后运行 git checkout 时调用。在那里你可以运行一个脚本来收集所有要忽略的文件并将它们保存在某个地方。

  • pre-commit:在获取建议的提交日志消息并进行提交之前,您可以运行第二个脚本来恢复这些文件的内容.

关于svn - 使用 Git 处理颠覆 : Ignoring modifications to tracked files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2562523/

相关文章:

git - 忘记推送并丢失更改

git - 有人在 M1 CPU Mac 上成功运行 git-svn 吗?

git - Subversion 中遗漏版本的可能性(研究环境)

git - 如何在 git 服务器端禁用压缩?

svn - 该客户端太旧,无法使用工作副本

git - 如何更新git子模块

git - 如何检测是否已应用 git 补丁?

git - 从 git-svn 迁移到 git 后,如何删除假的远程分支?

git - 所有 svn 修订号的映射 <=> git SHA-1 提交哈希

升级到1.7后svn客户端无法工作: working copy is too old