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

问题描述

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



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



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



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

解决方案

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

甚至 :


  • 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:

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处理颠覆:忽略对被追踪文件的修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 23:30