标签: gitattributes

使用git的word-diff来输入latex文件

我希望git diff输出所有文件的常规差异,除了*.tex.对于*.tex文件,我想看看输出git diff --word-diff.

我和玩弄.gitattributes.gitconfig,但我得到了最远的是得到一个.tex文件中的部分显示,随后坠毁.

有可能得到这种行为吗?

我的.gitattributes:

*.tex diff=latex
Run Code Online (Sandbox Code Playgroud)

.gitconfig:

[diff "latex"]
    wordRegex = "\\\\[a-zA-Z]+|[{}]|\\\\.|[^\\{}[:space:]]+"
    command = ~/bin/word-diff.sh
Run Code Online (Sandbox Code Playgroud)

并且word-diff.sh:

#!/bin/sh 
git --no-pager diff --color-words "$2" "$5"
Run Code Online (Sandbox Code Playgroud)

git gitattributes word-diff

10
推荐指数
1
解决办法
1228
查看次数

为什么'git status'会忽略.gitattributes清理过滤器?

我有一个.gitattributes清理过滤器,用于在提交之前删除文件中的所有注释.

$ cat .git/config
[filter "cleancomments"]
    clean = "grep -v '^#'"

$ cat .gitattributes
*   filter=cleancomments
Run Code Online (Sandbox Code Playgroud)

我有一个文件'test',其中包含以下内容(在存储库中提交):

This is a file with random content
Run Code Online (Sandbox Code Playgroud)

现在我对'test'进行修改并添加注释:

This is a file with random content
# and some comments
# like this
Run Code Online (Sandbox Code Playgroud)

git status 现在告诉我:

modified:   test
Run Code Online (Sandbox Code Playgroud)

但是git diff是空的(应该如此).

我不完全清楚为什么git status不使用过滤器来决定文件是否被修改,但我认为这是它的实现方式.

对我来说真正神秘的是:

如果我这样做:

git add test
Run Code Online (Sandbox Code Playgroud)

然后突然文件'test'不再标记为已修改,并且它不会出现在git索引中.为什么是这样?

git gitattributes

10
推荐指数
1
解决办法
1234
查看次数

git忽略.gitattributes模式

我有一个像这样的目录结构:

root/
  .git
  deploy/
  Site/
    blah/
    more_blah/
      something.local
      else.development
    Rakefile
    .gitattributes
Run Code Online (Sandbox Code Playgroud)

编辑:为了进一步说明上面的内容,目录有一个尾随,子目录/在目录下缩进,所以blah并且more_blah是目录但是Rakefile.gitattributes文件,但所有四个都是子目录Site.


我正在git-archive从这样的Site目录运行:

git archive --format=tar --prefix=git-v0.0.1/ v0.0.1 | gzip > ../deploy/git-v0.0.1.tar.zip
Run Code Online (Sandbox Code Playgroud)

但无论我放入.gitattributes的模式,生成的存档总是包含Rakefile.我试过了:

  • Rake文件
  • 网站/ Rake文件
  • */Rake文件
  • ./Rakefile
  • Rake文件*
  • *

它们都没有像我期望的那样工作.是否有人愿意指出明显但不明显的解决方案?任何帮助深表感谢.


我很抱歉不清楚.

  • 我说我使用的模式似乎不起作用,但我在模式后使用"export-ignore".
  • Rakefile 不是目录,只是一个文件
  • .gitattributes文件成功从存档中删除其他模式,Rakefile不是唯一使用的模式,但是唯一不起作用的模式.无论我是单独使用它还是使用其他模式,以及文件中的任何位置,它都不起作用.这不是真的,因为重命名某些文件但没有使用重命名归档提交我似乎得到了一些好的结果.我的错!:S

这是我.gitattributes(坐在目录中Site)

Rakefile        export-ignore
*.local         export-ignore
*.development   export-ignore
*.staging       export-ignore
Run Code Online (Sandbox Code Playgroud)

git gitattributes

8
推荐指数
2
解决办法
1万
查看次数

gitattributes没有正确设置合并驱动程序

我有以下目录结构:

project/
    .git/
        ...
    app/
        ...
    config/
        initializers/
            braintree.rb
        environments/
            production.rb
    .gitattributes
Run Code Online (Sandbox Code Playgroud)

我的项目使用两个主要分支,主分支和分段,每个分支跟踪不同的远程(生产和暂存heroku应用程序).

我们的想法是,分段分支随着新功能向前移动,它们被推送到临时远程控制台并进行测试,然后快速转发主分区以匹配分段并推送到生产远程.

这就是我想要做的事情:自由合并这两个分支,同时保持它们的版本braintree.rbproduction.rb分离.

为了实现这一点,这里是我提出的.gitattributes(根据ProGit书):

config/initializers/braintree.rb merge=ours
config/environments/production.rb merge=ours
Run Code Online (Sandbox Code Playgroud)

该文件存在于两个分支中.

我遇到的问题是,这似乎对任何事情没有任何影响.每当我在两者之间合并时,无论如何文件都会被更改,我必须再次更改它们.

我有一种感觉,我错过了一些非常明显的东西,但到目前为止它正在逃避我.我知道其他答案涉及创建自定义合并驱动程序,但ProGit书中没有提到这个过程,似乎暗示ours驱动程序是内置的(我已经在手册页中看到过它,所以我是相对确定它是).我能想到的另一件事就是我以某种方式放.gitattributes错了地方或弄乱了它的内容,但我找不到太多关于此的信息.我已经尝试将它移动到与文件相同的目录,但无济于事.

如果它有任何帮助,我在OS X上运行git版本1.7.2.任何帮助将不胜感激.

git git-merge gitattributes

8
推荐指数
1
解决办法
3205
查看次数

git archive:export-ignore,忽略目录

我有一个git存储库.gitattributes:

my_script.py export-subst
Makefile export-ignore
README.md export-ignore
.gitattributes export-ignore
.gitignore export-ignore
hooks/ export-ignore
tests/ export-ignore
*.pyc export-ignore
Run Code Online (Sandbox Code Playgroud)

但当我做:

git archive HEAD | tar -x -C ../archive_dir
Run Code Online (Sandbox Code Playgroud)

archive_dir目录中,我得到目录hookstests:

 ls ../archive_dir/
 hooks/  my_script.py tests/
Run Code Online (Sandbox Code Playgroud)

为什么?

我的git版本是1.7.9.

git gitattributes git-archive

8
推荐指数
1
解决办法
5266
查看次数

这个值在git中意味着什么?

在一个.gitattributes文件中,我找到了以下行

*.cs   text diff=csharp
Run Code Online (Sandbox Code Playgroud)

这是什么意思?

c# git gitattributes

8
推荐指数
1
解决办法
1168
查看次数

如何通过父项目中的.gitattributes将子行结尾强制转换为子模块中的LF?

我有一个存储库来存储我的所有Vim设置.它使用子模块来插入Pathogen的插件(我看过其他插件管理器,到目前为止没有兴趣).由于MSYSGit在为提交消息打开Vim时处理行结尾的方式,我需要将存储库与Unix行结尾一起存储(eol = lf).

我尝试在主仓库中添加一个带有内容的.gitattributes文件:

* eol=lf
* text=auto
Run Code Online (Sandbox Code Playgroud)

使用git rm --cached -r .和刷新主存储库后,主仓库中git reset --hard的行结尾现在是LF.但是,在子模块中运行相同的命令不起作用.

tl; dr:如何配置我的git repo以便用LF行结尾检出子模块?

git line-endings git-submodules gitattributes

8
推荐指数
1
解决办法
269
查看次数

在 gitattributes 中使用 `**/` 匹配目录

我原本期望**/匹配 git 存储库中的任何目录,但实际上它什么也不匹配。man gitattributes说:

匹配目录的模式不会递归匹配该目录内的路径(因此在属性文件中使用尾部斜杠 path/ 语法是没有意义的;请改用 path/** )

但就我而言,甚至与目录本身**/不匹配。我的意思是,如果我的仓库中有,那么甚至不匹配 dir 。我期望它匹配 dir但不匹配 file 。a/b.txt**/aaa/b.txt

如果我更改**/**,则目录及其内容都会匹配。在同一示例中,dira和 filea/b.txt都匹配。

那么 gitattributes 如何在目录上工作呢?如果 git 认为目录上的属性并不重要,那么为什么 git 在 的情况下列出它们**

git gitattributes

8
推荐指数
1
解决办法
5318
查看次数

git*text = auto在gitattributes文件和行结尾中

基于这篇文章: `.gitattributes`文件中`text = auto`的目的是什么?如果.gitattributes文件中包含以下内容,则 行结尾将转换为LF以用于文本文件:

* text=auto
Run Code Online (Sandbox Code Playgroud)

我刚刚在本地存储库上测试过:

$ git add -A
warning: LF will be replaced by CRLF in [bla]/.gitattributes.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in [bla]/.gitignore.
The file will have its original line endings in your working directory.
warning: LF will be replaced by CRLF in [bla]/README.md.
The file will have its original line endings in your working directory.
warning: LF …
Run Code Online (Sandbox Code Playgroud)

git gitattributes

7
推荐指数
1
解决办法
1371
查看次数

如何为其中包含空格的文件定义 .gitattributes 规则?

我已经阅读了.gitattributes 上的文档,并在 Stack Overflow 上搜索了这个问题的简单答案,但到目前为止还没有找到。我有一个文件,里面有空格,就像这样。

Reserved\ Slots.txt merge=mergeslots
Run Code Online (Sandbox Code Playgroud)

我还尝试使用引号而不是转义空格。

"Reserved Slots.txt" merge=mergeslots
Run Code Online (Sandbox Code Playgroud)

如何对包含空格的文件使用自定义合并驱动程序?

git merge gitattributes

7
推荐指数
1
解决办法
2048
查看次数