오류 없이 아무것도 커밋하지 않는 방법?
저는 다음과 같은 작업을 수행하는 패브릭 스크립트를 작성하려고 합니다.git commit
; 그러나 커밋할 것이 없으면 git은 다음 상태로 종료됩니다.1
. 배포 스크립트는 이를 실패한 것으로 간주하고 종료합니다.실제 커밋 실패를 감지하고 싶으므로 패브릭을 포괄적으로 무시할 수 없습니다.git commit
실패.빈 커밋 실패를 무시하여 배포는 계속할 수 있지만 실제 커밋이 실패할 때 발생하는 오류를 포착하려면 어떻게 해야 합니까?
def commit():
local("git add -p && git commit")
다음의 종료 코드를 확인하여 이 상태를 미리 파악합니다.git diff-index
?
예를 들어 (쉘에서):
git add -A
git diff-index --quiet HEAD || git commit -m 'bla'
편집: 고정git diff
Holger의 말에 따라 명령을 내립니다.
From thegit commit
man 페이지:
--allow-empty
Usually recording a commit that has the exact same tree as its
sole parent commit is a mistake, and the command prevents you
from making such a commit. This option bypasses the safety, and
is primarily for use by foreign SCM interface scripts.
토비 앤 홀거의 답변을 명시적으로 확장하는 것입니다.if
진술.
git add -A
if ! git diff-index --quiet HEAD; then
git commit -m "Message here"
git push origin main
fi
설명을 좀 해보죠.
git add -A
: 변경 사항 준비(다음 단계에 대한 required)git diff-index --quiet HEAD
단계별 변경 내용을 헤드와 비교합니다.--quiet
그것이 암시하듯이 중요합니다.--exit-code
"차이가 있으면 코드 1로 프로그램 종료를 makes하고 0은 차이가 없다는 것을 의미합니다."
참고 --조용히 하세요.
with settings(warn_only=True):
run('git commit ...')
이로 인해 패브릭이 장애를 무시하게 됩니다.빈 커밋을 만들지 않는 장점이 있습니다.
추가 레이어에 포장 가능합니다.with hide('warnings'):
출력을 완전히 억제합니다. 그렇지 않으면 패브릭 출력에 커밋이 실패했다는 메모가 표시됩니다(그러나 fab 파일은 계속 실행됩니다).
포탄을 통과할 때, 당신은 그것을 사용할 수 있습니다.... || true
실패가 예상되거나 무시됨을 선언하는 기법:
git commit -a -m "beautiful commit" || true
이를 통해 셸 스크립트를 사용할 때 셸 스크립트가 빠져나가는 것을 방지할 수 있습니다.errexit
선택.
대신에... || true
반환 코드가 0인 상태에서 종료되는 다른 명령어를 사용할 수도 있습니다. 예를 들어,
git commit -a -m "beautiful commit" || echo "ignore commit failure, proceed"
시도해 보세요/catch 베이비!
from fabric.api import local
from fabric.colors import green
def commit(message='updates'):
try:
local('git add .')
local('git commit -m "' + message + '"')
local('git push')
print(green('Committed and pushed to git.', bold=False))
except:
print(green('Done committing, likely nothing new to commit.', bold=False))
언급URL : https://stackoverflow.com/questions/8123674/how-to-git-commit-nothing-without-an-error
'programing' 카테고리의 다른 글
C(UB를 호출하지 않음)에서 두 개체가 겹치는지 확인할 수 있습니까? (0) | 2023.10.04 |
---|---|
토글 버튼은 어떻게 만드나요? (0) | 2023.10.04 |
"controller as" 구문으로 명명된 양식을 참조하는 방법 (0) | 2023.10.04 |
Jest.js 오류: "수신됨: 동일한 문자열로 직렬화" (0) | 2023.10.04 |
컨테이너에 로컬 파일을 사용하려면 어떻게 해야 합니까? (0) | 2023.10.04 |