We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
git
git 2.22 版本之后
git branch --show-current
git 2.22 版本之前
# 使用 rev-parse git rev-parse --abbrev-ref HEAD # 使用 symbolic-ref git symbolic-ref --short -q HEAD
如果当前处于一个提交(commit)而不是分支上时会有以下区别
rev-parse
HEAD
symbolic-ref
symbolic-ref 和 rev-parse 的区别
node
execa
const execa = require('execa') const branchName = execa.commandSync('git rev-parse --abbrev-ref HEAD').stdout
shelljs
const shell = require('shelljs') const branchName = shell .exec('git rev-parse --abbrev-ref HEAD', { silent: true }) .stdout.trim()
child_process
const child_process = require('child_process') const branchName = child_process .execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }) .trim()
可以根据分支名在 webpack 编译时做处理(如: 线上环境打包只允许在 master 分支)
webpack
master
The text was updated successfully, but these errors were encountered:
No branches or pull requests
获取当前
git
分支命令
如果当前处于一个提交(commit)而不是分支上时会有以下区别
rev-parse
子命令时会返回HEAD
symbolic-ref
子命令时会返回错误(空字符串)symbolic-ref 和 rev-parse 的区别
在
node
中使用execa
shelljs
child_process
用途
可以根据分支名在
webpack
编译时做处理(如: 线上环境打包只允许在master
分支)The text was updated successfully, but these errors were encountered: