![쉘 스크립트를 통해 Git 저장소의 마스터 브랜치가 원본 뒤에 있는지 확인하십시오.](https://linux55.com/image/149009/%EC%89%98%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EB%A5%BC%20%ED%86%B5%ED%95%B4%20Git%20%EC%A0%80%EC%9E%A5%EC%86%8C%EC%9D%98%20%EB%A7%88%EC%8A%A4%ED%84%B0%20%EB%B8%8C%EB%9E%9C%EC%B9%98%EA%B0%80%20%EC%9B%90%EB%B3%B8%20%EB%92%A4%EC%97%90%20%EC%9E%88%EB%8A%94%EC%A7%80%20%ED%99%95%EC%9D%B8%ED%95%98%EC%8B%AD%EC%8B%9C%EC%98%A4..png)
나는 현재 내 로컬 마스터 브랜치가 Origin/Master 뒤에 있다는 것을 발견했을 때 내 git 저장소를 리베이스하도록 상기시키기 위해 bash 스크립트를 작성하고 있습니다.
지금까지 나는 다음을 생각해 냈지만 $?
항상 반환됩니다 1
. (비어 있는 diff라도 여전히 로드되기 때문이라고 생각됩니다 less
.
#!/bin/bash
REPO_PATH=$1
cd $REPO_PATH
# flow once inside repo
{
git fetch
git diff master origin/master
} &> /dev/null
if [ "" = $? ]
then
echo "Empty"
# logic to follow
else
{
git pull
} &> /dev/null
echo "Don't forget to rebase!!!"
echo $REPO_PATH
fi
# check for changes to master
# If master is behind origin/master
# then pull master and notify me to rebase
# run this at the start of the day (this script should be run from my start_work
# script and should also be periodically run throughout the day. [maybe every
# time I'm about to run coverage/push?])
누구든지 어떤 아이디어가 있습니까?
답변1
당신은 사용해야합니다git-merge-base
시험 --is-ancestor
:
if git merge-base --is-ancestor origin/master master; then
echo Empty
else
echo "Don't forget to rebase!"
fi
답변2
종료 상태를 보는 대신 실제 출력을 볼 수 있습니다.
예를 들어
git fetch &> /dev/null
diffs=$(git diff master origin/master)
if [ -z "$diffs" ]
then
echo "Empty"