[Git] 커밋 시간 변경하기
1. 최근 커밋 날짜를 현재 날짜로 변경
$ git commit --amend --no-edit --date "$(date)"
2. 최근 커밋 날짜를 원하는 날짜로 변경
$ git commit --amend --no-edit --date "Fri 18 Feb 2022 01:35:10 KST"
3. REBASE
를 통한 커밋 날짜와 작성한 날짜 변경
1) rebase
를 진행할 커밋 지정
$ git rebase -i HEAD~1 # 가장 최근 커밋에 대하여 Rebase 진행
2) 커밋별 행위를 지정
해당 커밋을 수정하기 위해 pick
대신 아래와 같이 edit
명령어로 변경한다.
edit fc27d76 Commit Message
# Rebase 0b1301b..fc27d76 onto 0b1301b (1 command)
#
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# b, break = stop here (continue rebase later with 'git rebase --continue')
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
3) 커밋 시간 및 작성 시간 변경
$ GIT_COMMITTER_DATE= git commit --amend --no-edit --date "Fri 18 Feb 2022 01:35:10 KST"
$ GIT_AUTHOR_DATE= git commit --amend --no-edit --date "Fri 18 Feb 2022 01:35:10 KST"
4) 변경 내역 저장 및 rebase
종료
$ git rebase --continue
저장이 아닌 취소하고자 할 경우 --continue
대신 --abort
옵션을 사용하면 된다.
💡 Tip!
변경 후
GitHub
내 타임라인의 시간과 커밋 시간이 일치하지 않는 등 불일치한 경우가 발생할 때 아래와 같이 실행한다.$ git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"' # 특정 조건을 가진 커밋을 필터링하여 브랜치를 재정의 $ git push -f # 강제(Force) PUSH
* 참고자료: [git-filter-branch Documentation](https://git-scm.com/docs/git-filter-branch)
4. 수정이 필요한 커밋 이후에 커밋이 추가된 경우
$ git filter-branch -f --env-filter \
'if [ $GIT_COMMIT = {커밋 Hash값} ]
then
export GIT_AUTHOR_DATE="Fri 18 Feb 2022 01:35:10 KST"
export GIT_COMMITTER_DATE="Fri 18 Feb 2022 01:35:10 KST"
fi'
$ git push origin -f
Author And Source
이 문제에 관하여([Git] 커밋 시간 변경하기), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@be_have98/Git-커밋-시간-변경하기저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)