对Git,Mercurial和Bazaar使用相同的忽略文件是否安全? [英] Is it safe to use the same ignores file for Git, Mercurial, and Bazaar?

查看:169
本文介绍了对Git,Mercurial和Bazaar使用相同的忽略文件是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Git,Mercurial和Bazaar的忽略文件似乎都有类似的格式( .gitignore .hgignore .bzrignore [另见 bzr patterns] )。

为了提高全局忽略文件的同步性,它会是安全地使用一个作为一个实际的文件,并简单地将其他两个符号链接到该文件?换句话说,使我的 $ HOME / .gitignore 规范忽略文件和做



<$ p有任何危险$ p $ ln -s $ HOME / .gitignore $ HOME / .hgignore
ln -s $ HOME / .gitignore $ HOME / .bazaar / ignore

或者它们之间有一些细微的差别,会在某个时候咬我?

解决方案

忽略文件中使用的语法不同于系统:


  • Mercurial:正则表达式列表 - 可以使用语法进行更改:glob line。


  • Bazaar: shell shell模式列表 - 以 RE:作为前缀以匹配正则表达式。


  • Git: shell shell模式列表。




此外,shell模式和正则表达式如何匹配的确切规则因工具而异。总而言之,这意味着如果您的全局忽略文件非常简单,您只能希望使用这个技巧。正如你所说的那样,差异可能会随之而来,咬你。



我用这个文件测试了它:

 语法:glob 
.bzr
.git
.hg
* .o
*〜

,并且它似乎在所有三种工具中按照预期工作。为了测试它,我创建了这个目录树:

  $ tree 

| - foo.c
| - foo.c.〜1〜
| - foo.h
| - foo.o
` - - src
| - bar.c
| - bar.c.〜1〜
` - bar.o

并运行每个工具的状态命令:

  $ for工具在HG git bzr;请回显== $ tool status ==; $工具状态;完成
== hg status ==
? foo.c
? foo.h
? src / bar.c
== git status ==
#分支主

#初始提交

#未记录文件:
#(使用git add< file> ...来包含将要提交的内容)

#foo.c
#foo.h
# src /
没有添加到提交但未跟踪的文件存在(使用git add来跟踪)
== bzr状态==
未知:
foo.c
foo.h
src /

正如你所看到的,这个简单的文件工作正常。 / p>

从技术上讲,Git和Bazaar现在将忽略名为语法的文件:glob ,但除​​非您计划创建文件用那个奇怪的名字,这没关系。最后,请注意默认情况下,Mercurial不会读取 $ HOME / .hgignore 文件。但你可以通过添加

  [ui] 
ignore.my-default =〜/ .hgignore来读取它

添加到您的 $ HOME / .hgrc 文件。


Git, Mercurial, and Bazaar all seem to have similar formats for their ignore file (.gitignore, .hgignore, .bzrignore [see also bzr patterns]).

In order to improve synchronization of the global ignore files, would it be safe to use one as an actual file and simply symlink the other two to that file? In other words, is there any danger in making my $HOME/.gitignore the canonical ignores file and doing

ln -s $HOME/.gitignore $HOME/.hgignore
ln -s $HOME/.gitignore $HOME/.bazaar/ignore

or is there some subtle difference among them that would bite me at some point?

解决方案

The syntax used in the ignore files is different from system to system:

  • Mercurial: list of regular expressions — can be changed with a syntax: glob line.

  • Bazaar: list of shell glob patterns — prefixing with RE: to match as regular expression.

  • Git: list of shell glob patterns.

Furthermore, the exact rules for how the shell patterns and regular expressions are matched differ from tool to tool. All in all, this means that you can only hope to use this trick if your global ignore file is pretty simple. Otherwise the differences can come and bite you, as you say.

I tested it with this file:

syntax: glob
.bzr
.git
.hg
*.o
*~

and it seems to work as intended across all three tools. To test it, I created this directory tree:

$ tree
.
|-- foo.c
|-- foo.c.~1~
|-- foo.h
|-- foo.o
`-- src
    |-- bar.c
    |-- bar.c.~1~
    `-- bar.o

and ran the status command for each tool:

$ for tool in hg git bzr; do echo "== $tool status =="; $tool status; done
== hg status ==
? foo.c
? foo.h
? src/bar.c
== git status ==
# On branch master
#
# Initial commit
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       foo.c
#       foo.h
#       src/
nothing added to commit but untracked files present (use "git add" to track)
== bzr status ==
unknown:
  foo.c
  foo.h
  src/

As you can see, this simple file works fine.

Technically, Git and Bazaar will now ignore a file called syntax: glob, but unless you plan to create a file with that weird name, this doesn't matter. Finally, note that Mercurial doesn't read a $HOME/.hgignore file by default. But you can make it read it by adding

[ui]
ignore.my-default = ~/.hgignore

to your $HOME/.hgrc file.

这篇关于对Git,Mercurial和Bazaar使用相同的忽略文件是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆