Git Diff - 指示行移动

发布于 2024-10-04 09:39:07 字数 218 浏览 6 评论 0原文

我正在开发一个与 git diff 一起使用的脚本,以便能够“过滤掉”只是在文件中移动的行。使用 Designer 文件时,Visual Studio 2008 已成为一种痛苦。有时它似乎坚持以不同的顺序重写整个文件。这使得很难看到文件的真正更改。我将 git diff 通过管道传输到脚本中以调整 git diff 的输出。我可以从输出中删除这些行,也可以用不同的符号替换 +/- 来指示移动,但我不确定要使用哪些符号。

I'm developing a script to use with git diff to be able to 'filter out' lines that have simply moved in a file. Visual Studio 2008 has become a pain when working with Designer files. It sometimes seems to insist on rewriting the entire file in a different order. This makes it difficult to see the real changes to the file. I'm piping git diff into a script to tweak the output of git diff. I could either remove the lines from the output or I could replace the +/- with different symbols to indicate a move but I'm not sure which symbols to use.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

终遇你 2024-10-11 09:39:07

这不是问题的答案,而是所描述问题的可能的替代解决方案。

我不熟悉 Visual Studio 2008 或设计器文件,但我遇到了一个想要存储文件的解决方案在 git 中由另一个程序生成。某些文件中的行顺序根本不重要。在其他文件中,顺序并不重要,但简单的排序是不够的,因为它包含嵌套的数据结构。

我的解决方案是利用 git 中的过滤器在提交之前更改文件内容。它被配置为两部分。首先,您需要使用 .gitattributes 文件。

*.list      filter=sort

接下来需要在配置文件中定义过滤器的行为。这可以在用户配置 ~/.gitconfig 中完成,也可以在存储库配置 .git/config 中完成。这仅是本地的,不会作为存储库的一部分自动与其他人共享,因此如果您希望其他人也这样做,那么您需要告诉他们。

[filter "sort"]
    clean = sort
    smudge = cat

这个简单过滤器的结果是,当文件提交到存储库时,这些行不是按创建它们的程序的随机顺序排列,而是按字母数字排序,并且只有添加、删除和更改出现在差异中。

现在我提到我有两种不同的文件类型可以使用,一种是简单的,一种是复杂的。对于包含嵌套数据类型(具体来说是 Lua 表)的复杂数据类型,我创建了(在其他人的大量帮助下)一个脚本来读取文件内容,对每个嵌套部分进行排序,并在不改变行为的情况下输出排序结果当数据后来被使用时。

This is not an answer to the question but a possible alternative solution to the problem described.

I'm not familiar with Visual Studio 2008 or Designer files but I have run into a solution where I wanted to store files in git that were being generated by another program. The order of lines in some of the files didn't matter at all. In other files, the order was not important but a simple sort was inadequate because it contained nested data structures.

My solution was to make use of filters in git to alter the file contents before they were committed. This is configured in two parts. First you need to assign a filter to the files using a .gitattributes file.

*.list      filter=sort

Next the behavior of the filter needs to be defined in the config file. This can either be done in your user config ~/.gitconfig, or in the repos config .git/config. This is local only and not shared with others automatically as part of the repo so if you want others to do this too then you need to tell them.

[filter "sort"]
    clean = sort
    smudge = cat

The result of this simple filter was that when the files were committed to the repo, instead of the lines being in the random order from the program that created them, they were sorted alphanumerically and only additions, removals, and changes appeared in the diffs.

Now I mentioned that I had two different file types two work with, a simple one and a complex one. For the complex one which contained nested datatypes (Lua tables to be specific), I created (with a lot of help from somebody else) a script to read the file contents, sort each nested section, and output the sorted result without altering the behavior when the data was later used.

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