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 [email protected]
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 [email protected]
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 <[email protected]>
Date: Fri Nov 17 13:06:07 2017 +0100
Added submodule
commit 03a935df578a2eaf3f42789bd1e89e313224797a
Author: tester1 <[email protected]>
Date: Fri Nov 17 13:06:06 2017 +0100
changed both in master
commit d617db69dd9468e88587e2363050fdf57ac10756
Author: tester1 <[email protected]>
Date: Fri Nov 17 13:06:06 2017 +0100
changed both in master1
commit 88a07e5c887d63ead4e6cedd6349dfaf85ec1866
Author: tester1 <[email protected]>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With