Very wierd. If I run this command interactively, I see the expected result:
git branch --contains c46b341b72509a02ee1c1a489a7f9b37d477c4f5
* v2Tunnel
But if I try to capture this in a variable, what gets captured is the names of some (but not all) files in the current folder, followed by the expected branch name (v2Tunnel is not a file in my directory)
CCC=$(git branch --contains c46b341b72509a02ee1c1a489a7f9b37d477c4f5)
# OR
CCC=`git branch --contains c46b341b72509a02ee1c1a489a7f9b37d477c4f5`
echo $CCC
IWiNS README.md cicommit citest v2Tunnel
Other git commands to not have this result:
CCC=`git rev-parse --abbrev-ref HEAD`
echo $CCC
v2Tunnel
You captured * v2Tunnel
in CCC
so when you do echo $CCC
the shell interprets that *
and lists local files.
To prevent shell to interpret *
use double quotes:
echo "$CCC"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.