使用 Git 处理 subversion:忽略对跟踪文件的修改
我目前正在使用 subversion 存储库,但我正在使用 git 在我的计算机上本地工作。它使工作变得更加容易,但也使 subversion 存储库中发生的一些不良行为变得非常明显,这给我带来了问题。
拉取代码后,有一个有点复杂的本地构建过程,它创建(并且不幸的是修改)许多文件。显然,这些更改并不意味着要提交回存储库。不幸的是,构建过程实际上正在修改一些跟踪文件(是的,很可能是因为有人在某个时候错误地将这些构建工件提交到了 subversion 存储库)。由于这些是修改,将它们添加到我的忽略文件中对我没有任何作用。
我可以避免检查这些更改,我只是简单地不暂存或提交它们,但是未暂存的本地更改意味着我无法在不先清理它们的情况下进行变基。
我想知道是否有任何方法可以忽略对一组跟踪文件的未来更改?或者,是否有另一种方法来处理我遇到的问题,或者我只需告诉签入这些文件的人来清理它们?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如内森所说,清理这些文件(取消跟踪它们)是明智之举。
但是,如果您必须忽略跟踪文件(这不是忽略文件的本机 Git 方式:Git 只忽略非跟踪文件),您可以设置一个过程来复制您想要的文件内容忽略,并在提交时恢复。
我最初相信涂抹/清洁过程,这是 gitattributes 过滤器驱动程序 可以做到这一点:
,其中:
但是,如 本文中提到,这意味着通过添加有状态上下文(即文件的完整路径名)来滥用此无状态文件内容转换弄脏/干净)。
JC Hamano 明确禁止这样做:
甚至 Linus Torvalds 当时对 all 机制也有一些保留:
所以添加某种保存/恢复机制的正确位置(并有效地忽略对一组跟踪的任何更改 Git 中的文件)将位于 hooks 中:
post-checkout
:更新工作树后运行 git checkout 时调用。您可以在那里运行一个脚本,收集所有要忽略的文件并将它们保存在某个地方。预提交
:您可以运行第二个脚本,该脚本将在获取建议的提交日志消息并进行提交之前恢复这些文件的内容。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:
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:
and even Linus Torvalds had some reservations at the time about the all mechanism:
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 忽略对跟踪文件的更改。
Unless there's some serious political brain damage going on, removing the artifacts from source control is the correct step. (Or rather, "most expedient" step, it's always the correct step.)
I not aware of a way to tell git to ignore changes to tracked files.