Programing

git 태그 (또는이를 기반으로 한 GitHub 릴리스)의 날짜 변경

lottogame 2020. 9. 14. 21:35
반응형

git 태그 (또는이를 기반으로 한 GitHub 릴리스)의 날짜 변경


메인 브랜치의 다양한 커밋에 태그를 추가하여 GitHub의 프로젝트에 릴리스추가 하고 있습니다.

내 프로젝트 중 하나에서 시간 순서대로 커밋에 태그를 추가하지 않았습니다. (명백한 커밋을 찾아서 태그를 지정한 다음 덜 분명하고 오래된 커밋을 찾아서 태그를 지정했습니다.)

이제 GitHub는 v1.0.1을 현재 버전으로 표시하고 v0.7.0이 앞에 있고 v1.1.2 .

태그가 지정된 커밋 대신 태그 생성 날짜를 릴리스 날짜로 사용하는 것으로 보입니다. 태그를 지정하는 커밋과 날짜가 동일하도록 태그를 편집하려면 어떻게해야합니까?

gitk와 GitHub 간의 릴리스 및 날짜 매핑


경고 : 주석이 달린 태그에 대한 태그 메시지는 보존 되지 않습니다 .

요약

변경해야하는 각 태그에 대해 :

  1. 태그를 나타내는 커밋으로 시간을 거슬러 올라갑니다.
  2. 태그 삭제 (로컬 및 원격)
    • 이렇게하면 GitHub의 "릴리스"가 나중에 삭제할 수있는 초안으로 바뀝니다.
  3. 날짜를 커밋 날짜로 설정하는 매직 호출을 사용하여 동일한 이름의 태그를 다시 추가합니다.
  4. 날짜가 고정 된 새 태그를 GitHub에 다시 푸시합니다.
  5. GitHub로 이동하여 현재 초안 릴리스를 삭제하고 새 태그에서 새 릴리스를 다시 만듭니다.

코드에서 :

# Fixing tag named '1.0.1'
git checkout 1.0.1               # Go to the associated commit
git tag -d 1.0.1                 # Locally delete the tag
git push origin :refs/tags/1.0.1 # Push this deletion up to GitHub

# Create the tag, with a date derived from the current head
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a 1.0.1 -m"v1.0.1"

git push --tags                  # Send the fixed tags to GitHub

세부

Git에서 태그하는 방법에 따르면 :

릴리스 또는 버전 범프에 태그를 지정하는 것을 잊은 경우 언제든지 다음과 같이 소급하여 태그를 지정할 수 있습니다.

git checkout SHA1_OF_PAST_COMMIT
git tag -m"Retroactively tagging version 1.5" v1.5

그리고 그것은 완벽하게 사용할 수 있지만, "최신"태그를 찾는 빌드 시스템을 망칠 수있는 시간순으로 태그를 배치하는 효과가 있습니다. 그러나 두려워하지 마십시오. Linus는 모든 것을 생각했습니다.

# This moves you to the point in history where the commit exists
git checkout SHA1_OF_PAST_COMMIT

# This command gives you the datetime of the commit you're standing on
git show --format=%aD  | head -1

# And this temporarily sets git tag's clock back to the date you copy/pasted in from above
GIT_COMMITTER_DATE="Thu Nov 11 12:21:57 2010 -0800" git tag -a 0.9.33 -m"Retroactively tagging version 0.9.33"

# Combining the two...
GIT_COMMITTER_DATE="$(git show --format=%aD  | head -1)" git tag -a 0.9.33 -m"Retroactively tagging version 0.9.33"

그러나 이미 태그를 추가 한 경우 위와 함께 사용할 수 없습니다. git tag -f existingtag그렇지 않으면 병합을 시도 할 때 git이 불평 할 것입니다.

Rammy:docubot phrogz$ git push --tags
To git@github.com:Phrogz/docubot.git
 ! [rejected]        1.0.1 -> 1.0.1 (already exists)
error: failed to push some refs to 'git@github.com:Phrogz/docubot.git'
hint: Updates were rejected because the tag already exists in the remote.

대신 로컬에서 태그를 제거해야합니다.

git tag -d 1.0.1

삭제를 원격으로 푸시 :

git push origin :refs/tags/1.0.1

GitHub에서 릴리스 (이제 릴리스가 "초안"으로 표시됨)를 다시로드하고 초안을 제거하십시오.

이제 위의 지침에 따라 이전 태그를 추가하고 마지막으로 결과 태그를 GitHub에 푸시합니다.

git push --tags

그런 다음 GitHub 릴리스 정보를 다시 추가하십시오.


다음은 다른 답변의 일부 주석을 기반으로 한 한 줄입니다.

git tag -l | while read -r tag ; do COMMIT_HASH=$(git rev-list -1 $tag) && GIT_COMMITTER_DATE="$(git show $COMMIT_HASH --format=%aD | head -1)" git tag -a -f $tag -m"$tag" $COMMIT_HASH ; done && git push --tags --force

WARNING: this will nuke your upstream tags and will not preserve messages for annotated tags! Be sure that you know what you're doing and DEFINITELY don't do this for a public repository!!!

To break it down...

# Loop over tags
git tag -l | while read -r tag
do

    # get the commit hash of the current tag
    COMMIT_HASH=$(git rev-list -1 $tag)

    # get the commit date of the tag and create a new tag using
    # the tag's name and message. By specifying the environment
    # environment variable GIT_COMMITTER_DATE before this is
    # run, we override the default tag date. Note that if you
    # specify the variable on a different line, it will apply to
    # the current environment. This isn't desired as probably
    # don't want your future tags to also have that past date.
    # Of course, when you close your shell, the variable will no
    # longer persist.
    GIT_COMMITTER_DATE="$(git show $COMMIT_HASH --format=%aD | head -1)" git tag -a -f $tag -m"$tag" $COMMIT_HASH


done

# Force push tags and overwrite ones on the server with the same name
git push --tags --force

Thanks to @Mr_and_Mrs_D for the suggestion to use a single push.


Building on the other answers, here's a way that will preserve the first line of the tag message

git tag -l | while read -r tag ; do COMMIT_HASH=$(git rev-list -1 $tag) COMMIT_MSG=$(git tag -l --format='%(contents)' $tag | head -n1) && GIT_COMMITTER_DATE="$(git show $COMMIT_HASH --format=%aD | head -1)" git tag -a -f $tag -m"$COMMIT_MSG" $COMMIT_HASH ; done
git tag -l -n1           #check by listing all tags with first line of message
git push --tags --force  #push edited tags up to remote

The bit responsible for preserving the messages is:

COMMIT_MSG=$(git tag -l --format='%(contents)' $tag | head -n1)

head -n1 will take the first line of the old commit message. You can modify it to -n2 or -n3 etc to get two or three lines instead.

If you want to change the date/time for just one tag, this is how you can break down the one-liner to do it in your bash shell:

tag=v0.1.0
COMMIT_HASH=$(git rev-list -1 $tag)
COMMIT_MSG=$(git tag -l --format='%(contents)' $tag | head -n1)
COMMIT_DATE=$(git show $COMMIT_HASH --format=%aD | head -1)
GIT_COMMITTER_DATE=$COMMIT_DATE git tag -s -a -f $tag -m"$COMMIT_MSG" $COMMIT_HASH

References:

참고 URL : https://stackoverflow.com/questions/21738647/change-date-of-git-tag-or-github-release-based-on-it

반응형