使用Git处理颠覆:忽略对被追踪文件的修改 [英] Using Git to work with subversion: Ignoring modifications to tracked files

查看:100
本文介绍了使用Git处理颠覆:忽略对被追踪文件的修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Subversion版本库,但我正在使用git在本地机器上工作。它使工作变得更容易,但它也使得在颠覆回购中发生的一些不良行为相当明显,并且给我带来了麻烦。



有一点复杂拉下代码后创建本地构建过程,并创建(并不幸修改)一些文件。很明显,这些更改并不意味着被提交回存储库。不幸的是,构建过程实际上是在修改一些跟踪文件(是的,很可能是因为有人错误地将这些构建工件提交给了Subversion存储库)。因为这些修改将它们添加到我的忽略文件中对我没有任何帮助。



我可以避免检查这些更改,我简单地不要分阶段或提交它们,但如果没有第一次清理它们,我就不能重新分配。



我想知道的是,如果有什么办法可以忽略对一组跟踪文件?或者,是否有另一种方式来处理我遇到的问题,或者我将只需告诉谁检查了这些文件来清理它们?

解决方案

As ,这将意味着通过添加一个有状态的上下文(即,无状态文件 content
这是JC Hamano明确禁止的:


虽然我最初考虑使用路径名插入%P ,但我最终决定不使用它,以阻止人们滥用过滤器进行状态转换,从而根据时间更改结果,路径名,提交,分支和东西。


甚至 Linus Torvalds当时对所有机制都有一些保留:


我必须说,我显然不是玩游戏的狂热粉丝,但差异非常小。



他们真的很有用吗?

我不知道。我对这个功能的任何实际用户意味着什么感到有点紧张,但我不得不承认被干净的实现所迷惑。



我怀疑这会让我们有些抱怨,但我也怀疑人们最终会真的因为这样的事情而自责然后指责我们,并在我们支持这一做法时引发巨大的痛苦,并且人们希望扩展语义不再干净。



但我不确定真实的论证有多有效。我确实相信给他们绳子的理念。我认为你可以用这种方式来大肆宣传自己,但是,嘿,任何一个只会责怪自己的人







因此,添加某种保存/恢复机制(并且有效地忽略Git中一组跟踪的文件>的任何更改)的正确位置将位于 钩子


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

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

I am currently working with a subversion repository but I am using git to work locally on my machine. It makes work much easier, but it also makes some of the bad behavior going on in the subversion repo quite glaring and that creates problems for me.

There is a somewhat complex local build process after pulling down the code and it creates (and unfortunately modifies) a number of files. Obviously these changes are not meant to be committed back to the repository. Unfortunately the build process is actually modifying some tracked files (yes, most likely because someone mistakenly committed these build artifacts at some point to the subversion repository). Since these are modifications adding them to my ignore file does nothing for me.

I can avoid checking these changes back it, I simple don't stage or commit them, but having unstaged local changes means I can't rebase without first cleaning them up.

What I would like to know is if there any way to ignore future changes to a set of tracked files? Alternatively, is there another way to handle the problem I am having, or will I just have to tell whoever checked in these files to clean them up?

解决方案

As Nathan said, cleaning up those files (un-tracking them) is the smart move.

But if you must ignore tracked files (which is not the native Git way when it comes to ignoring files: Git only ignores non-tracked files), you can setup a process copying the content of files you want to ignore, and restoring on commit.

I initially believed that a smudge/clean process, that is a gitattributes filter driver could do the trick:

, where:

  • the smudge process will make a copy of those files (when updating the working tree)
  • some modifications take place during the build
  • the clean step (during commit) will erase the files content with the copy made in step 1.

BUT, as stated in this post, that would mean abusing this stateless file content transformation by adding a stateful context (i.e. the full path name of the file being smudged/clean).
And that is explicitly forbidden by 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.

and even Linus Torvalds had some reservations at the time about the all mechanism:

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


So the right place to add some kind of save/restore mechanism (and effectively ignoring any changes to a set of tracked files in Git) would be in hooks:

  • post-checkout: invoked when a git checkout is run after having updated the worktree. There you can run a script collecting all the files to ignore and saving them somewhere.

  • pre-commit: you can run a second script which will restore the content of those files, before obtaining the proposed commit log message and making a commit.

这篇关于使用Git处理颠覆:忽略对被追踪文件的修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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