任何使用Git别名而不是git- *脚本的理由? [英] Any reason to use a Git alias instead of a git-* script?

查看:104
本文介绍了任何使用Git别名而不是git- *脚本的理由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Git中,您可以使用别名或通过创建可执行文件(包含在PATH中)来创建自定义命令,从 git - 开始。是否有任何理由选择别名而不是脚本?

In Git, you can create custom commands using either an alias or by creating an executable file, included in your PATH, starting with git-. Is there any reason to choose an alias as opposed to a script?

我与一个开发团队合作,并且已经制作了一些我想与他们分享的方便别名。我的同事建议别名应该用于简单的事情,比如缩短命令(例如 git co <​​/ code>作为 git checkout ),而且这些脚本可以用于更复杂的任务,比如将多个函数合并为一个。但他不能拿出任何理由不使用脚本,也不知道他应该如何感觉,或者他是否听说过应该是这样,或者是什么。

I work with a team of developers and have made some handy aliases I'd like to share with them. A colleague of mine suggested that aliases should be used for simple things, like shortening a command (e.g. git co as an alias for git checkout), and that scripts would be useful for more complicated tasks, like combining multiple functions into one. But he couldn't come up with any reason why not to use scripts, not sure if it's just how he felt it should be, or if he had heard somewhere that that's how it should be, or what.

我们的团队都在同一个开发服务器上工作,所以如果我可以使用脚本,我可以简单地将它放在 / usr / local / bin

Our team all works on the same development server, so if I can use a script, I can simply put it in /usr/local/bin and everyone will have access to it automatically. So even with a simple alias, it would be much more convenient to just have it as a git script so that everyone automatically has it, as opposed to me having to tell everyone to set it up individually. Not to mention, when a new developer starts, we would have to remember to have them set it up as well.

我知道这听起来像我为脚本方法,我是。我只是想知道是否有任何缺点使用该方法。

I know it sounds like I'm campaigning for the script approach, and I am. I'm just wondering if there is any drawback to using that approach.

推荐答案

别名是通过git的配置机制定义的,所以他们根据您是在 / etc / gitconfig 〜中定义它们,可以应用于整个系统,单个用户或单个存储库。 /.gitconfig $ GIT_DIR / config 。如果将自己的.gitconfig复制到新机器上,它将通过复制单个文件来包含所有个人别名,这比复制完整目录和设置 PATH 正确地找到你的文件。

Aliases are defined via git's config mechanism, so they can apply to either the whole system, a single user, or just a single repository, depending on whether you define them in /etc/gitconfig, ~/.gitconfig or $GIT_DIR/config. If you copy your own .gitconfig to a new machine, it will include all your personal aliases by copying a single file, which seems less overhead than copying a full directory and setting up PATH correctly to find your files.

这篇关于任何使用Git别名而不是git- *脚本的理由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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