Git on Mac: -a command isn't working - macos

I'm trying to commit all files in a directory, using the git commit -a "added some change" command.
I'm working on Mac OS X, Leopard.
After I submit the command, the Terminal responds with:
fatal: Paths with -a does not make sense.
Could someone please tell me if there's anything I'm doing wrong?

In git one uses the -m option to add a message. -a means all thus commits all changed files
type in your terminal:
git add -a -m "Added some change"
For future problems see
git commit -h
(... omitted output)
-m, --message <message>
commit message
(... omitted output)
Commit contents options
-a, --all commit all changed files
(... omitted output)

try git commit -am "some message"

Related

How to use git alias with shell function to build a commit message

I'm trying to create a git alias to automate my PR merge and approval.
The complete git command is this:
git checkout master && git sync && git merge --no-ff -m 'Merged in hotfix/X-3144 (pull request #1112)' remotes/origin/hotfix/X-3144
Where X is the BitBucket prefix for the issue. Reading other stack overflow questions, I came up with this:
mergeto = "!f() { git checkout $1 && git sync && git merge --no-ff -m 'Merged in {$2}/B2B-{$3} (pull request #{$4})' remotes/origin/$2/X-$3;}; f "
So, naturally I'm using this to merge a PR that has conflicts. After I resolve these conflicts, I issue a git commit and git brings up nano with my previously typed commit message. My goal here is that the commit message is constructed using my parameters. So, for an example, if I use:
git mergeto master hotfix 123 1120
My final commit message was supposed to be "Merged in hotfix/X-123 (pull request #1120)" but instead I get a "Merged in {$2}/X-{$3} (pull request #{$4})"
How can I specify the parameters in such a way that this can work?
I Read a few stack over flow posts that show how to use a shell function inside a git alias, but couldn't find an example of escaping the text with parameters.
Using John Szakmeister and eftshift0 suggestions, I got it working by escaping double quotes with backlash:
mergeto = "!f() { git checkout $1 && git sync && git merge --no-ff -m \"Merged in $2/B2B-$3 (pull request #$4)\" remotes/origin/$2/X-$3;}; f "
Thanks for your help!

git log with square bracket in name

I'm trying to get the log for a file with square brackets in its name. In case it matters: the OS is Windows and i'm using git bash.
If you create a file with [] in its name like [Start_here].bat then git log will not work.
I tried:
git log '[Start_here].bat'
git log \[Start_here\].bat
git log '\[Start_here\].bat'
git log -- '[Start_here].bat'
git log -- \[Start_here\].bat
git log -- '\[Start_here\].bat'
And none of them seemed to work. Either it did not display any commits or displayed a list of unrelated commits.
Does anybody have a solution that works?
Note:
git mv '[Start_here].bat' 'start_here.bat'
git log --follow start_here.bat
does show me a history in which the file was changed.
Edit:
Using the following script executed in a new repo I can see git log behaving correctly untill you add a submodule. Then it starts listing all the commits that changed a submodule too...
#!/usr/bin/env bash
set -x
rm -rf test-repo
rm -rf test-submodule
mkdir test-submodule
pushd test-submodule
git init
git config --local user.name tester1
git config --local user.email test#here.com
echo "a single line" > file.txt
git add file.txt
git commit -m "first commit"
popd
mkdir test-repo
pushd test-repo
git init
git config --local user.name tester1
git config --local user.email test#here.com
git branch -m master
echo "first line" > somefile.txt
git add somefile.txt
git commit -m "First line"
echo "another line" >> somefile.txt
git add somefile.txt
git commit -a -m "Second line"
echo "A line" > "[__Odd__].txt"
git add "[__Odd__].txt"
git commit -m "Adding odd file"
echo "third line" >> somefile.txt
git commit -a -m "Another bold statement."
echo "2nd line" >> "[__Odd__].txt"
echo "more" >> somefile.txt
git add "[__Odd__].txt" somefile.txt
git commit -m "changed both in master1"
git checkout -b new_branch
echo "2nd line" >> "[__Odd__].txt"
echo "more" >> somefile.txt
git add "[__Odd__].txt" somefile.txt
git commit -m "changed both in new_branch"
git checkout master
echo "2nd line" >> "[__Odd__].txt"
echo "more" >> somefile.txt
git add "[__Odd__].txt" somefile.txt
git commit -m "changed both in master"
git submodule add -- ../test-submodule module
git commit -m "Added submodule"
git log -- "[__Odd__].txt"
This outputs:
commit c3ebc7e0daf68543d761fc3b06c7ab35e014efaf (HEAD -> master)
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:07 2017 +0100
Added submodule
commit 03a935df578a2eaf3f42789bd1e89e313224797a
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:06 2017 +0100
changed both in master
commit d617db69dd9468e88587e2363050fdf57ac10756
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:06 2017 +0100
changed both in master1
commit 88a07e5c887d63ead4e6cedd6349dfaf85ec1866
Author: tester1 <test#here.com>
Date: Fri Nov 17 13:06:05 2017 +0100
Adding odd file
Notice the top entry, it should not be here. It is related only to the submodule not to the file i want the log for.
git log -- somefile.txt does not output changes related to the submodules
In CMD, try:
git log -- "[__Odd__].txt"
or
git log -- ./"[__Odd__].txt"
Proof: https://imgur.com/7qqsVJ6
If everything fails, you can install WSL, and use git for tricky situations there.
Update 1 - From the comments:
you, sir, have found a bug in git for windows! I can reproduce your git log, and I can't reproduce it in WSL using linux's git, but can reproduce it using git.exe within WSL!
Filed a report: github.com/git-for-windows/git/issues/1371, let's see what comes of it
Update 2: This was a real bug in the code Git software, which has been fixed due to this question! How amazing 🎉 is that?!?!
Git on Windows comes in two flavors:
one using the Bash shell, and another using DOS.
The former is called Git Bash, the latter Git Cmd.
In Git Bash, git log '[foo]' should work.
In Git Cmd, git log "[foo]" should work (this also works in Git Bash btw).
In a DOS shell, you cannot use single-quotes to enclose strings that contain special characters.
(Special in the sense of "special to the shell".)
In Bash you can.
This is why, it looks like you are using Git Cmd.
Also keep in mind that auto-completion is your friend.
Both Git Bash and Git Cmd can auto-complete path names.
For example in Git Cmd if you start typing git log "[ and then press TAB,
it should give you some options to auto-complete.
If you start typing git log '[ and then press TAB,
it won't give you any options.
That's how you know the syntax is already wrong and you can stop typing and try another way.
I just tested, with Git 2.15 for Windows, the double-quotes.
It works with git bash:
vonc#VONCAVN7:/mnt/d/git/talks$ git log -- "[r].txt"
commit 7a698bf83cb55fa479200a3585b03ece1ee5db0a (HEAD -> 201710_docker)
Author: VonC <vonc#laposte.net>
Date: Mon Nov 13 20:33:04 2017 +0100
test
Or directly from a CMD shell session:
vonc#VONCAVN7 D:\git\talks
> git log -- "[r].txt"
commit 7a698bf83cb55fa479200a3585b03ece1ee5db0a (HEAD -> 201710_docker)
Author: VonC <vonc#laposte.net>
Date: Mon Nov 13 20:33:04 2017 +0100
test
To be sure you don't have any other program interfering with Git, try the same Git log after having set a simplified PATH.

Multiple git commands in single command executed in order they are encountered by compiler

I have following list of commands that I run in respective order so that a source project can be committed and pushed to the repository on Bitbucket:
git init
git remote add origin https://[BitBucket Username]#bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git
git config user.name "[BitBucket Username]"
git config user.email "[BitBucket Email ID]"
## if email doesn't work then use below ##
git config --global user.email \<\>
git add *
git commit -m "[Comment]"
git push -u origin master
Now instead of putting each and every line at their respective time and order, I want to know, if there is a possibility that I can chain all these into single git command and maintain the same order, something like below ?
git init remote add origin https://[BitBucket Username]#bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git config user.name "[Username]" ....
Or atleast combine multiple same category params like below ?
git config user.name "[BitBucket Username]" user.email "[BitBucket Email ID]"
I need to know possibility of both scenarios with examples.
We can use list off command in single command for example:
git add . && git commit -m "updated pom file" && git push
or:
git stash pop && git add . && git commit -m "updated pom file" && git push
&& -> if 1st command successfully executes then execute next command else it won't execute next command.
& - it executes all the command
|| - execute next command if 1st one failed
If you are in a Windows Powershell:
git add . ; git commit -m "Testing one line command" ; git push
I have gitbash on Windows system and I am not as good with Win batch as with Linux shell.
You still can write a bash script (interpreted by the msys2 bash embedded with Git for Windows).
As mentioned in the comments by Lasse V. Karlsen, and as I mentioned before in "Which shell used for git '!' aliases?", you can write a shell script in a file (in your %PATH%) named git-xxx, and call it with git xxx.
That script would begin with:
#!/bin/bash
I created a file called reset.txt and in that file I have the commands
git reset --hard
git clean -d -f
[this is a newline - very important to have it]
I just copy and paste this into my terminal and it executes the commands in order.

Add new command on Windows Git Bash

I would like to add new command on my Git Bash (just now i am under Windows OS). I tryed to look on Web different solutions but I did not find anything. The command that i like to add is:
commitall -> git add --all && git commit -m "$*"
There is a way to add this command on Windows Git Bash?
Thanks
Use Git aliases, like so:
git config --global alias.commitall '!git add --all && git commit -m'
There's no need to use $* because all the arguments you specify will simply be appended to the line above, i.e. if you run:
git comitall "a message"
…the following will be executed:
git add --all && git commit -m "a message"

.bashrc strange warning "lias command not found"

I have a following .bashrc file:
function lazygit() {
git add --all :/
git commit -a -m "$1"
git push
}
function bak() {
git pull
git add --all :/
git commit -a -m "backup: $1"
git push
}
But whenever I call lazygit or bak command, I get:
/home/bok/.bashrc: line 1: lias: command not found
Already up-to-date.
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
/home/bok/.bashrc: line 1: lias: command not found
Everything up-to-date
Why do I get "lias: command not found"?
Open /home/bok/.bashrc and goto line #1. You will see lias and change to alias (the a was probably accidentally deleted).
Close your terminal completely and re-open it. It should work fine now.

Resources