[Git] commit 날짜 수정
rebase 명령어를 통해 과거로 돌아가봅시다
![[Git] commit 날짜 수정](https://cdn.hashnode.com/res/hashnode/image/unsplash/BXOXnQ26B7o/upload/v1649001774804/qICw6f5HU.jpeg)
git rebase -i로 원하는 commit 고르기
git rebase -i --root
위 명령어를 실행하면 vi가 열리는데 원하는 commit을 pick에서 edit으로 바꾸고 :wq로 저장하면 commit이 선택된다.
git log 명령어의 결과를 통해 지금 선택된 commit을 알 수 있다.
commit 날짜 수정하기
git commit --amend --no-edit --date "Mon Mar 28 20:11:36 2022 +0900"
data 부분에 들어갈 날짜를 원하는 날짜 및 시간으로 수정하면 된다.
git rebase --continue
만약 날짜를 바꾸고 싶은 commit이 한 개 이상이라 여러 개를 edit으로 바꾸었다면 git rebase --continue로 다음 commit으로 넘어갈 수 있다.
모종의 이유로 rebase를 멈추고 싶다면
git rebase --abort를 사용하면 된다
다 바뀐게 아니다?
이 부분은 의도된 것이긴 한데 rebase로 commit을 수정하면 AuthorDate는 바뀌지만 CommitDate는 바뀌지 않는다.
git log --pretty=fuller
commit 1347db1ffc44e621d645bd76a52126b3761760d2
Author: Yun Seongmin <ilcm96@gmail.com>
AuthorDate: Mon Mar 28 20:11:36 2022 +0900
Commit: Yun Seongmin <ilcm96@gmail.com>
CommitDate: Sun Apr 3 22:58:16 2022 +0900
Initial commit
위와 같이 AuthorDate는 바뀌었지만 CommitDate는 그대로인 것을 볼 수 있다.
이를 수정하기 위해서는 git filter-branch를 사용해야 한다.
git filter-branch --env-filter 'export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"'
GIT_COMMITTER_DATE를 GIT_AUTHOR_DATE로 덮어 씌운다는 명령어로 이 명령어를 실행하면 AuthorDate와 CommitDate가 같아지게 된다.
git push
이렇게 변경한건 강제로 push를 해줘야 한다
git push origin +main
위와 같이 브랜치명 앞에 +를 붙이면 강제로 push된다.
Comments
Join the discussionNo comments yet. Be the first to comment.




