问题标签 [git-alias]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
200 浏览

git - Echos in gitconfig aliases echoing the entire list of command line arguments when only one expected

For a long time, I had the following alias in my aliases file:

It wasn't original to me, and if you search for it, you'll see it a lot of places. Recently, however, I've started having a weird problem with the alias. Anything I ignore gets placed twice in the .gitignore file and on the same line (with a space only).

I did a bit of debugging and found that what is really happening is that the call to echo $1 is echoing $1 as you'd expect, but also echoing the entire string of arguments to the alias.

To test this, I made a new alias:

That last line is the most interesting because it clearly shows that the echo call is getting the entire set of arguments tacked on to it while $1 is getting evaluated correctly. In fact, if I mess with things and change $1 to $9 (and don't fill $9), I get:

I have confirmed that this happens on Git versions 1.8.5 to 1.9.0 and I have confirmed that it DOES NOT happen in Git version 1.7.1; unfortunately, I am unable to test between 1.7.1 and 1.8.5.

Does anyone have any insight to what is going on here? It breaks a few of my aliases...

0 投票
2 回答
4367 浏览

git - 未知开关 'm' 与 git 别名提交

在我的 .gitconfig 中,我有以下别名:

这个想法是添加所有更改并提交它们。但是,我没有成功,因为 Git 正在给我消息error: unknown switch 'm'

0 投票
1 回答
383 浏览

git - Git 配置文件局部变量

我有一组不同类型日志的别名,例如:

日志别名有很多种,但大多数都使用相同的格式。如何使用公共部分的内容定义局部变量?

理想情况下,我想避免为此使用环境变量

0 投票
1 回答
97 浏览

git - .gitconfig 格式的 git 别名

我尝试做与此处描述的几乎相同的操作,但存在相同的问题:

创建带有格式的“git log”别名

当然,这个主题的解决方案是有效的。

但是假设我想将我的 git 函数分组到 git 命名空间中,即运行git gl "some time ago". 但是当我尝试直接在 .gitconfig 中定义函数时:

gl = "!f() { git log --all --pretty=format:'%h %cd %s (%an)' --since="$1"; }; f",

我有和以前一样的错误 - fatal: ambiguous argument ...lalala...

即使在 .bash_profile 中定义函数并从 git 别名调用时也会发生同样的情况。

使用“全局”函数问题不大,但我想知道,为什么会这样?是否有可能在 .gitconfig 中定义这样的功能?

0 投票
1 回答
28 浏览

configuration - Git:为“add --update TOPLEVEL_DIR”创建别名?

我经常发现自己在打字

旨在添加所有已修改但在整个存储库中跟踪的内容。但是,当我在子目录中时,它会变得烦人且乏味。例如,如果我所有的修改都在src/但我当前在test/util目录中,那么我需要输入

这容易出错且速度慢(因为我需要计算../脑海中的数量)。

我想创建一个 git 别名au,以便它自动检测顶层(通常是包含目录的路径中的第一个祖先.git目录)。它不必是完全可移植的,因为我使用来自bash. 有任何想法吗?

0 投票
0 回答
75 浏览

windows - Git 脚本函数 (Windows) 中的命令在 Git 存储库下的子文件夹中未按预期工作

我有以下文件夹结构...

我正在尝试纠正 .gitconfig 文件中的脚本函数,我需要知道当前目录,但我的行为很奇怪。

对于我的所有测试,我打开了一个托管 Windows PowerShell 的 Console2 窗口来运行我的 git 命令。

提示符下,如果我键入$pwd,它会“正确”显示 C:\GitRepo\IgnoredFolder\SubRepo。我说“正确”,但它是 Windows 格式而不是 *Nix。

在我的 .git 配置中,我创建了这个别名:

现在,如果我在提示符下键入git test,我会得到 /c/GitRepo 的“不正确”显示。我说“不正确”,因为忽略 Windows 与 *Nix 格式,我本来希望/喜欢它返回 /c/GitRepo/IgnoredFolder/SubRepo。

其他命令的行为方式相同(即在包含 .git 存储库的第一个文件夹中操作,而不是在当前工作目录中操作。

例如,我想创建的真正别名基本上是 init、add、commit、remote、config 全部在一个命令中的快捷方式。伪别名看起来像这样......

但它不是在当前目录(我想要“操作”的新 SubRepo 文件夹)上运行,而是在包含 git repo 的第一个祖先文件夹(在本例中为 c:\GitRepo)上运行。

有没有办法让 git 别名脚本函数在当前目录上工作,无论它是否可以在包含 repo 的文件夹中找到?

提前致谢。

0 投票
2 回答
158 浏览

githooks - 我如何要求 git 将分支合并回父级

有没有办法编写将分支合并回其父级的别名?我知道我可以做到:

但它只适用于我以前的分支是父分支的简单情况。据我所知,git 不会跟踪此类信息,因为那里没有分支。但我希望它已经实现为插件或钩子集。
提前致谢。

0 投票
2 回答
649 浏览

git - Git alias for combining multiple commands: git checkout and git status

I find that every time I checkout a local branch, I do a git status. I want to add a git status to my alias for checkout to be more efficient.

I already have the following simple alias for checkout:

I'd like to modify it so that no matter what arguments I provide to 'git co', it will always perform:

So for example, I could any of the following, and the alias should perform a git status afterwards:

0 投票
1 回答
78 浏览

git - 在 Git 上配置别名

我想在一行中创建多个命令。例子:

有可能吗?

这是我的 .gitconfig:

0 投票
1 回答
50 浏览

git - 是否有一种可靠的方法来检查预期的 Git 别名是否可用?

Git 允许您创建自己的自定义 Git 动词或别名,使用

但是,如果您对 Git 命令不是很熟悉,您可以选择与现有 Git 动词对应的别名;作为一个非常愚蠢的例子,考虑

未恐慌; 根据git config --help

为了避免脚本使用的混乱和麻烦,隐藏现有 Git 命令的别名将被忽略。

很好,但是,在这种情况下,Git 不会告诉您您的新别名将被忽略

因此,我想知道在实际定义别名之前,是否有一种强大的(并且面向未来的)方法来检查我的预期别名是否对应于现有的 Git 动词。

我正在考虑<alias-name>在 的输出中搜索git help --all,但后者包含的不仅仅是所有 Git 动词的列表,所以我不确定这种方法有多强大......

任何想法?