I have the problem with macOS mojave, but I guess it generalizes to all bash environment. In the .bashrc or .profile, I add one line as:
alias gc="git add .;git commit --message="$(date +"iMac_%D_%T")""
My purpose is to send the current system time as a message when commiting a change by typing gc. However, the system time was read when alias was invoked (here is when I log in the system). Can anyone help me out? Thank you in advance!
Advertisement
Answer
The simpler approach is to make this a shell function and not an alias at all:
gc() { git add . && git commit --message="$(date +"iMac_%D_%T")" "$@" }
That said, as a matter of good git
hygeine, I strongly advise against doing this; you’ll get output files and temporary files you don’t want checked in. git commit -a
, by not adding new files, is somewhat safer — though using git add -p
to review changes hunk-by-hunk is by far the best practice to avoid mixing unrelated and unwanted changes into your commits.