CI/CD中可能使用的git命令

1.

获得pr分支相较于主分支所做的变更

搜集commit:

merge非rebase:git log origin/main..HEAD

rebase非merge:git log main..HEAD

仅收集特定路径下的更改

git log origin/main..HEAD -- pacakges/*

搜集更改文件

不包括状态: git diff --name-only origin/main..HEAD

包括状态(M,D,U): git diff --name-status origin/main..HEAD

1.

在大型项目中,会使用git clone --depth=1来减少拉取数量。这个时候会缺失main分支,和之前的tag信息,此时需要恢复

恢复main分支: git fetch origin main:main

恢复当前分支: git fetch --unshallow

1.

发布版本会同时打上tag,tag的相关操作:

查询指定tag

git describe --tags --abbrev=6666 --match

git for-each-ref --sort=-creatordate --format '%(refname:short)' refs/tags | grep


键入'/'获得帮助




Show


键入'/'获得帮助


键入'/'获得帮助

jsx
...
import { spawn } from 'child_process';

export async function execCommand(
commands: string,
// eslint-disable-next-line no-console
onData: ((type: string, v: string) => void) | null = console.log.bind(console)
) {
const childProcess = spawn('sh', ['-c', commands]);
let ans = '';
childProcess.stdout?.on('data', chunk => {
const str = chunk.toString();
if (onData) onData('data', str);
ans += str;
});
childProcess.stderr?.on('data', _error => {
if (_error) {
const error = _error.toString();
const str = `child process[${commands}] error:\n${error.toString()}`;
if (onData) onData('error', error);
ans += str;
}
});
let handler: ((v: { code: number | null; out: string }) => void) | null =
null;
childProcess.on('close', code => {
if (handler) {
handler({
code,
out: ans,
});
handler = null;
}
});

return new Promise<{ out: string; code: number | null }>(res => {
handler = res;
});
}



键入'/'获得帮助