요약 : git merge-base --is-ancestor
은 하나의 커밋이 다른 커밋의 조상인지 테스트합니다. 커밋은 그 자체의 조상으로 간주되며 특히 근친상간의 기이 한 형태입니다 (아마도 :-)). 현재 브랜치 (HEAD
)가 다른 커밋의 조상 인 커밋을 가리킬 때 브랜치 레이블은 git merge
에 의해서만 빨리 감기 될 수 있으므로 이것을 사용하여 git merge
이 빨리 감기 작업을 수행 할 수 있는지 여부를 결정할 수 있습니다.
답변으로 게시되기를 원했던 것처럼 보입니다. 따라서 전 세계의 git 구성에 넣을 수있는 작동하는 별칭으로 변환했습니다.별명은 약간 길고 복잡하고 그것은 아마 잘라 내기 및 붙여 넣기하여 자식 설정 별칭 섹션에이를 위해 최선을 다 할 것입니다 : 더에, 여기
canff = "!f() { if [ $# -gt 0 ]; then b=\"$1\"; git rev-parse -q --verify \"$b^{commit}\" >/dev/null || { printf \"%s: not a valid commit specifier\n\" \"$b\"; return 1; } else b=$(git rev-parse --symbolic-full-name --abbrev-ref @{u}) || return $?; fi; if git merge-base --is-ancestor HEAD \"$b\"; then echo \"merge with $b can fast-forward\"; else echo \"merge with $b cannot fast-forward\"; fi; }; f"
쉘 스크립트로 작성 같은 일이다 읽을 패션, 일부 논평 :
이
#! /bin/sh
#
# canff - test whether it is possible to fast-forward to
# a given commit (which may be a branch name). If given
# no arguments, find the upstream of the current (HEAD) branch.
# First, define a small function to print the upstream name
# of the current branch. If no upstream is set, this prints a
# message to stderr and returns with failure (nonzero).
upstream_name() {
git rev-parse --symbolic-full-name --abbrev-ref @{u}
}
# Now define a function to detect fast-forward-ability.
canff() {
local b # branch name or commit ID
if [ $# -gt 0 ]; then # at least 1 argument given
b="$1"
# make sure it is or can be converted to a commit ID.
git rev-parse -q --verify "$b^{commit}" >/dev/null || {
printf "%s: not a valid commit specifier\n" "$b"
return 1
}
else
# no arguments: find upstream, or bail out
b=$(upstream_name) || return $?
fi
# now test whether git merge --ff-only could succeed on $b
if git merge-base --is-ancestor HEAD "$b"; then
echo "merge with $b can fast-forward"
else
echo "merge with $b cannot fast-forward"
fi
}
쉘 스크립트는 단지 그것을 구동하기 위해 메인 섹션을 필요로 별칭 후 f
에 대한 호출입니다. 별칭 자체는 canff
및 upstream_name
의 모든 내용을 한 줄로 간단하게 삽니다. Git의 config 파일 규칙은 전체 별칭을 큰 따옴표로 인용해야하며, 차례로 모든 내부 큰 따옴표를 백 슬래시 - 큰 따옴표로 변환해야합니다.
는
은 (그것은 쓰기 실제로 가능 (별칭으로,이 쉘의 때마다 새로운 인스턴스를 발사 이후는, 그래서 변수 이름의 위생. 중요하게는 local b
문을했다) 별칭을 여러 줄로 사용합니다. 각 줄 바꿈 앞에 백 슬래시를 붙이기 만하면됩니다. 그러나이 별칭은 너무 복잡하여 그 것처럼 보이지 않으므로 하나의 큰 줄을 남겨 두었습니다.)
[가능한 자식이 있습니까? -merge --dry-run option?] (http://stackoverflow.com/questions/501407/is-there-a-git-merge-dry-run-option) – Vishwanath