使用 Git 处理 subversion:忽略对跟踪文件的修改

发布于 2024-08-27 18:57:30 字数 423 浏览 10 评论 0原文

我目前正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

↙厌世 2024-09-03 18:57:30

正如内森所说,清理这些文件(取消跟踪它们)是明智之举。

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

我最初相信涂抹/清洁过程,这是 gitattributes 过滤器驱动程序 可以做到这一点:

alt text

,其中:

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

但是,如 本文中提到,这意味着通过添加有状态上下文(即文件的完整路径名)来滥用此无状态文件内容转换弄脏/干净)。
JC Hamano 明确禁止这样做:

虽然我最初考虑用路径名插入“%P”,但我最终决定反对它,以阻止人们滥用过滤器进行状态转换,根据时间、路径名、提交来更改结果、分支等等。

甚至 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:

alt text

, 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.

ˇ宁静的妩媚 2024-09-03 18:57:30

除非发生严重的政治脑损伤,否则从源代码控制中删除工件是正确的步骤。 (或者更确切地说,“最权宜”的步骤,它始终是正确的步骤。)

我不知道有什么方法可以告诉 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文