쉘 스크립트를 통해 Git 저장소의 마스터 브랜치가 원본 뒤에 있는지 확인하십시오.

쉘 스크립트를 통해 Git 저장소의 마스터 브랜치가 원본 뒤에 있는지 확인하십시오.

나는 현재 내 로컬 마스터 브랜치가 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"

관련 정보