问题
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 that?
回答1:
The following works for me:
git init --bare $HOME/.dotfiles
touch $HOME/.dotfiles/.test
git config --global alias.ac '!git add -A && git commit -m'
git config --global alias.dot '!git --git-dir=$HOME/.dotfiles/ $HOME/.dotfiles'
git dot ac "Commit message"
The dot
command also works in combination with last
and stash-and-reset
.
git dot last
4c1db03 (HEAD -> master) testtest
P.S. I didn't set --work-tree=$HOME
because I would get too many files, but it would work.
Another way to solve your problem is to create a bash alias
to track your dotfiles, this can also be used in combination with other git commands and aliases. See for instance this article!
来源:https://stackoverflow.com/questions/64416625/can-not-use-some-of-my-aliases-with-bare-repo