水星忽略文件 [英] Mercurial ignore file

查看:91
本文介绍了水星忽略文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Mercurial忽略配置文件,但是我无法使其正常工作.

I'm trying to get Mercurial to ignore a configuration file, but I'm failing to get it working.

我已使用hg init在服务器上创建了一个存储库,并将该存储库克隆到了我的计算机上.然后,我希望能够编辑configurationj文件,但不将那些更改提交回服务器.

I have created a repository on my server with hg init and cloned that repository to my computer. I then want to be able to edit the configurationj file but not commit those changes back to the server.

我尝试在克隆的根目录中创建一个.hgignore,但是Mercurial使用?标记该文件,并且无论是否提交,它仍会继续记录我的配置更改.

I have tried creating a .hgignore in the root of my clone, but Mercurial flags the file with a ? and whether I commit it or not it still continues to log my configuration changes.

我在错误的位置创建了.hgignore文件,是否需要提交该文件?在服务器上初始化存储库之前是否需要创建它?

Am I creating the .hgignore file in the wrong place, does this file need to be commited? Does it need to be created before I init the repository on the server?

推荐答案

  • .hgignore不需要在初始化之前创建
  • 该配置文件将由其他人使用,您最好提交.hgignore,这样其他人就不必创建它,但这不是必需的,这样可以忽略本地文件(请参阅例子)
  • 是的.hgignore必须位于根目录中
    • .hgignore does not need to be created before init
    • It the config file will be used by others, you'd better commit the .hgignore so others dont have to create it, but this is not needed for mercurial to ignore your local files (see example)
    • Yes .hgignore has to be in the root directory
    • 初始化仓库:

      $ mkdir test 
      $ cd test 
      $ hg init 
      

      创建文件

      $ touch foo 
      $ hg st 
      ? foo 
      

      现在,在仓库的根目录中创建一个.hgignore:

      Now create a .hgignore, in the root directory of your repo:

      $ echo 'foo' > .hgignore 
      

      foo现在被忽略:

      $ hg st 
      ? .hgignore 
      

      请注意,无需启用.hgignore即可.

      Note that .hgignore does not need to be committed for this to work.

      如果在回购中同时提交了配置文件和.hgignore(忽略配置文件),则可以,将跟踪配置文件的更改(换句话说,.hgignore将无效)

      If both the config file and a .hgignore (ignoring the config file) are committed in the repo, then yes, the config file changes will be tracked (in other words, .hgignore will have no effect)

      创建配置并提交

      $ touch config
      $ hg ci config -Am 'adding conf'
      

      忽略它:

      $ echo 'config' >> .hgignore
      

      提交.hgignore:

      Commit .hgignore:

      $ hg ci .hgignore -Am '.hgignore'
      

      然后,如果您克隆存储库:

      Then if you clone the repo:

      $ cd ..
      $ hg clone test other-user
      $ cd other-user
      

      并修改配置:

      $ echo 'new config param' >> config
      

      然后hg将显示更改:

      $ hg st
      M config
      

      如何处理?

      您可能想要在存储库global.cfg

      然后您将要求用户创建一个local.cfg并将其放置本地设置的位置.如果存在,您的脚本将提供local.cfg的来源:本地设置会覆盖全局设置.当然,在.hgignore上添加一行以忽略local.cfg;)

      And you will ask users to create a local.cfg where they will put their local settings. And your script will source the local.cfg if present: the local settings override the global ones. Of course, add a line to .hgignore to ignore local.cfg ;)

      替代:没有全局配置文件,只有用户在本地复制和修改的config.example.这样做的缺点是您不会轻易跟踪版本之间的更改.

      Alternative: no global config file, only a config.example that users copy and modify locally. The con here is that you will not keep track easily of changes between versions.

      这篇关于水星忽略文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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