may*_*may 6 git bash alias aliases
我正在尝试在 ubuntu 中添加以下别名
alias l=log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short
$ source ~/.aliases
bash: alias: --decorate: not found
bash: alias: --decorate: not found
bash: alias: --numstat: not found
Run Code Online (Sandbox Code Playgroud)
我可以在外面用 git 使用这个命令
我不太确定为什么?有人能帮我吗?我尝试过谷歌搜索,但并没有走得太远。我对 bash 不太了解。
这是一个有点老的问题,但理解和创建 git 别名非常重要,因为这会节省你的大量时间。
在您的问题中,您几乎要回答一个愚蠢的错误,那就是您试图使用脚本创建别名。
需要在.gitconfig文件中定义别名。不仅仅是别名,还有所有配置部分,例如
[core],[color],[pack],[help],[alias]ETC
我想与您分享一些基本且有用的别名,以便方便使用,您可以根据您的需要和日常使用情况进一步更改它
[alias]
lg = log -p
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
st = status
co = checkout
ci = commit -a -m
br = branch
ls = ls-files
po = push origin
f = fetch
p = pull
delete = branch -d master
com = checkout master
cob = checkout -b
unstage = reset HEAD
url = remote set-url origin
ign = ls-files -o -i --exclude-standard
cp = cherry-pick
Run Code Online (Sandbox Code Playgroud)
您还可以为单个命令中的多个 git 命令的组合创建别名,例如:
rdev = !git checkout dev && git pull && git checkout - && git rebase dev
Run Code Online (Sandbox Code Playgroud)
如果需要任何其他理解,请告诉我。
你快到了。您只需将别名放入正确的文件中即可。因为如果您部分键入命令,Git 不会自动推断您的命令,因此您可以使用以下命令轻松地为每个命令设置别名git config如下所示:
git config --global alias.co checkout\ngit config --global alias.br branch\ngit config --global alias.ci commit\ngit config --global alias.st status\nRun Code Online (Sandbox Code Playgroud)\n\n然后你使用它的别名,如:git ci, git co, git br,git st。
您还可以通过别名运行外部命令。在这种情况下,您可以使用!。如果您编写自己的与 Git 存储库一起使用的工具,这非常有用:
git config --global alias.visual \'!gitk\'\nRun Code Online (Sandbox Code Playgroud)\n\n您可能还注意到该config命令接受多个参数(如--global1)。如果我们查看文档man git config:
\n\n\n对于写入选项:写入全局 ~/.gitconfig 文件而不是存储库 .git/config,如果 $XDG_CONFIG_HOME/git/config 文件存在且 ~/.gitconfig 文件不存在\xe2\x80\x99t,则写入 $XDG_CONFIG_HOME/git/config 文件。\ n 对于读取选项:仅从全局 ~/.gitconfig 和 $XDG_CONFIG_HOME/git/config 中读取,而不是从所有可用文件中读取。\n 另请参阅名为 \xe2\x80\x9cFILES\xe2\x80\x9d 的部分。
\n
还有--system,它写入/etc/gitconfig,--local,用于本地存储库.git/gitconfig,并且--worktree,它类似于--local。
但您可以直接编辑文件本身。它看起来类似于:
\n\n# in ~/.gitconfig\n[alias]\n lg = log --all --stat --pretty=oneline --graph --format=\'%h %d %an %cr %s\' --oneline\n l = log --all --stat --graph --format=\'%h %d %an %cr %s\'\n up = pull --rebase\n br = branch --verbose -a\n sfp = push --force-with-lease\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
6235 次 |
| 最近记录: |