git-alias

Creating a git alias containing bash command substitution and an argument

安稳与你 提交于 2021-02-05 11:27:07
问题 Got this: git diff $(git status -s | awk 'FNR == $LINE_NUM {print $2}') ...where line number is the file output by status. Now I want to create an alias for this command in .gitconfig : [alias] diff-num = $WHAT_SHOULD_I_PUT_HERE? I want this alias to run git's diff command based on the line number argument I'll type in on the command line. I'm new to bash and I'm not sure if I need a bash function to handle this or how to pass the argument into the substituted command. 回答1: The usual form for

can not use some of my aliases with bare repo

限于喜欢 提交于 2021-01-29 14:32:16
问题 I have some aliases like: add-and-commit = !git add -A && git commit -m last = !git --no-pager log -1 --oneline stash-and-reset = !git stash && git reset --hard HEAD I track my dotfiles with a bare repo. d = !git --git-dir=/media/blueray/WDPurple/_DataBackup/_Work/_DailyBackups/dotfilesBackup --work-tree=$HOME Now the problem is that, i can use: git add-and-commit git last git stash-and-reset But I can not do: git d add-and-commit git d last git d stash-and-reset Is there any solution for

git - multiline function as alias is not working

℡╲_俬逩灬. 提交于 2021-01-29 11:37:30
问题 I have written a function which beautify the git log output (to solve the problem mentioned in different color for data and time in git log output). function gl() { my_date=(); my_time=(); while IFS= read -r line; do my_date+=( $(date +"%d-%m-%Y" -d @$line) ) my_time+=($(date +"%H:%M" -d @$line)) done < <( git log --format="%at" ) for (( n=0; n<${#my_date[@]}; n++ )); do git --no-pager log -1 --skip=$n --pretty=format:"%C(#d33682)%h %C(#859900)${my_date[$n+1]} %C(#b58900)${my_time[$n+1]} %C(

GitConfig: bad config for shell command

☆樱花仙子☆ 提交于 2020-01-24 09:23:54
问题 I'm trying to set up an alias, as I have many. For some reason, this one does not work. Any idea? [alias] t = "!git log --decorate --oneline | egrep '^[0-9a-f]+ \(tag: ' | sed -r 's/^.+tag: ([^ ]+)[,\)].+$/\1/g'" Command works fine by itself: $ git log --decorate --oneline | egrep '^[0-9a-f]+ \(tag: ' | sed -r 's/^.+tag: ([^ ]+)[,\)].+$/\1/g' 1.0.0 0.9.0 ... $ git t fatal: bad config file line 28 in /Users/alanschneider/.gitconfig 回答1: Backslash (" \ ") characters are read by git itself in

What is the meaning of the “bang” or “!” before the git command?

老子叫甜甜 提交于 2020-01-13 07:54:46
问题 As you can see from this excerpt, there is a "!" before the git command. What's the point? [alias] commitx = !git add . && git commit - https://stackoverflow.com/a/8956546/1354543 I understand aliases and what the command itself is doing, but not the point of the "!" before the git command. 回答1: The ! means "run the following as commands to the shell", so in this case the alias git commitx expands to the equivalent of running git add . && git commit (which is a terrible terrible idea) 回答2: An

git alias: multiple commands, variadic parameters

橙三吉。 提交于 2020-01-03 16:50:02
问题 I often find myself typing this: git push remote1 branch1 branch2 tag1 tag2 tag3.. git push remote2 branch1 branch2 tag1 tag2 tag3.. I would prefer an alias where I can type this instead: git pushall branch1 branch2 tag1 tag2 tag3 .. Note: I am aware I could create a new remote "all" with multiple urls. Let's not discuss this here, but focus on the alias instead! I am ok to hardcode the remote names, because I have a number of projects with the same multiple remote names (usually "drupal" and

Pass an argument to a Git alias command

风流意气都作罢 提交于 2019-12-28 01:52:06
问题 Can I pass arguments to the alias of a Git command? I have some alias in Git config, like so: rb1 = rebase -i HEAD~1 rb2 = rebase -i HEAD~2 rb3 = rebase -i HEAD~3 rb4 = rebase -i HEAD~4 .... Is it possible to make an rb alias so that git rb <x> works for any <x> ? I tried this alias: rb = rebase -i HEAD~ but then for instance git rb 8 does not work. 回答1: If you consider the Git Faq section "Git Aliases with argument", you could do it, but by calling git through a shell: [alias] rb = "!sh -c \

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

陌路散爱 提交于 2019-12-24 04:45:11
问题 For a long time, I had the following alias in my aliases file: ignore=!([ ! -e .gitignore ] && touch .gitignore) | echo $1 >>.gitignore 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

Git alias to add prefix to name of new branch

家住魔仙堡 提交于 2019-12-13 01:15:13
问题 Is there a way to write an alias that adds current date to name of new branch? For example: git branch-today new_branch_name should create new branch with 22_09_2015_new_branch_name name. 回答1: Create a git alias and add it to your .gitconfig [alias] branch-today = "!bt() { git branch $(date +%d-%m-%Y)_$1;}; bt" git branch-today foo Git branch output: 22-09-2015_foo * master 来源: https://stackoverflow.com/questions/32719966/git-alias-to-add-prefix-to-name-of-new-branch

git bad config when piping commands

不羁岁月 提交于 2019-12-13 00:05:43
问题 Both of these commands work from the command line git symbolic-ref HEAD | sed -e "s#^refs/heads/##" and git branch | grep \* | cut -d ' ' -f2 When added to gitconfig under [alias] thisbranch = !git symbolic-ref HEAD | sed -e "s#^refs/heads/##" thisbranch2 = !git branch | grep \* | cut -d ' ' -f2 I get fatal: bad config line 16 in file /Users/<me>/.gitconfig which is the second line. My initial problem was getting the current branch into an alias thanks to this answer. So I am mainly curious