Git에서 이전 커밋에 태그를 지정하는 방법은 무엇입니까?
우리는 git을 처음 접했고 저장소 시작 부분에 태그를 설정하고 싶습니다. 우리의 프로덕션 코드는 시작 저장소와 동일하지만 그 이후로 커밋을했습니다. 처음에 태그를 사용하면 프로덕션을 알려진 안정적인 상태로 "롤백"할 수 있습니다.
그렇다면 임의의 오래된 커밋에 태그를 추가하는 방법은 무엇입니까?
예:
git tag -a v1.2 9fceb02 -m "Message here"
9fceb02
커밋 ID의 시작 부분은 어디에 있습니까 ?
그런 다음을 사용하여 태그를 푸시 할 수 있습니다 git push origin v1.2
.
git log
현재 분기의 모든 커밋 ID를 표시 할 수 있습니다 .
Pro Git 책에는 태그 지정 에 대한 좋은 장도 있습니다.
경고 : 이렇게하면 현재 날짜로 태그가 생성 됩니다 (예를 들어 GitHub 릴리스 페이지에 표시되는 값). 태그에 커밋 날짜로 날짜를 지정하려면 다른 답변을 참조하십시오 .
코드 만
# Set the HEAD to the old commit that we want to tag
git checkout 9fceb02
# temporarily set the date to the date of the HEAD commit, and add the tag
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" \
git tag -a v1.2 -m"v1.2"
# set HEAD back to whatever you want it to be
git checkout master
세부
@dkinzer의 답변 은 커밋 날짜가 아닌 현재 날짜 ( git tag
명령 을 실행했을 때) 인 태그를 생성합니다 . 에 대한 Git 도움말 에는 다음과 같은 "백 데이트 태그" 섹션이 있습니다 .tag
다른 VCS에서 일부 변경 사항을 가져 왔고 작업의 주요 릴리스에 대한 태그를 추가하려는 경우 태그 개체 내부에 포함 할 날짜를 지정할 수 있으면 유용합니다. 태그 개체의 이러한 데이터는 예를 들어 gitweb 인터페이스의 태그 순서에 영향을줍니다.
향후 태그 개체에 사용되는 날짜를 설정하려면 환경 변수를 설정합니다
GIT_COMMITTER_DATE
(가능한 값에 대한 이후 설명 참조, 가장 일반적인 형식은 "YYYY-MM-DD HH : MM").예를 들면 :
$ GIT_COMMITTER_DATE="2006-10-02 10:31" git tag -s v1.0.1
"How to Tag in Git" 페이지 는 다음을 통해 HEAD 커밋 시간을 추출 할 수 있음을 보여줍니다.
git show --format=%aD | head -1
#=> Wed, 12 Feb 2014 12:36:47 -0700
다음을 통해 특정 커밋의 날짜를 추출 할 수 있습니다.
GIT_COMMITTER_DATE="$(git show 9fceb02 --format=%aD | head -1)" \
git tag -a v1.2 9fceb02 -m "v1.2"
그러나 커밋을 두 번 반복하는 대신 HEAD를 해당 커밋으로 변경하고 두 명령 모두에서 암시 적으로 사용하는 것이 더 쉽습니다.
git checkout 9fceb02
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a v1.2 -m "v1.2"
이를 수행하는 가장 간단한 방법은
git tag v1.0.0 f4ba1fc
와 f4ba1fc
태그에 원하는 커밋의 해시의 시작 인과 v1.0.0
당신이 태그에 원하는 버전 인.
사용 명령 :
git tag v1.0 ec32d32
여기서 v1.0은 태그 이름이고 ec32d32는 태그를 지정할 커밋입니다.
완료되면 다음과 같이 태그를 푸시 할 수 있습니다.
git push origin --tags
참고:
Git (개정 제어) : GitHub에서 특정 이전 커밋 지점에 태그를 지정하려면 어떻게해야합니까?
좋습니다 . 간단하게 다음을 수행 할 수 있습니다.
git tag -a <tag> <commit-hash>
따라서 tag : 1.0.2 to commit 을 추가하려면 다음을 e50f795
수행하십시오.
git tag -a 1.0.2 e50f795
또한 다음과 같이을 사용하여 끝에 메시지 를 추가합니다-m
.
git tag -a 1.0.2 e50f795 -m "my message"
결국, 당신은 그것을 푸시해야합니다 remote
.
git push origin 1.0.2
하나씩 언급하고 싶지 않은 태그가 많은 경우 다음을 수행하십시오.
git push origin --tags
모든 태그를 함께 푸시하려면 ...
또한 단계를 더 명확하게하기 위해 아래 이미지의 단계를 만들었습니다.
Hub 에서 태그를 dd 또는 SourceTree 와 같은 도구를 사용 하여 이전 단계를 피할 수도 있습니다. 이 경우 Bitbucket 에 로그인 한 다음 거기에서 수행합니다.
- Go to your branch and find the commit you want to add the tag to and click on it:
- In the commit page, on the right, find where it says
No tags
and click on the+
icon:
- In the tag name box, add your tag:
- Now you see that the tag has successfully created:
This is an old question, and the answers already given all work, but there's also a new option which can be considered.
If you're using SourceTree to manage your git repositories, you can right-click on any commit and add a tag to it. With another mouseclick you can also send the tag straight to the branch on origin.
Building upon the answers of the others, here is a one-liner solution that sets the tag date to when it actually happened, uses annotated tag and requires no git checkout
:
tag="v0.1.3" commit="8f33a878" bash -c 'GIT_COMMITTER_DATE="$(git show --format=%aD $commit)" git tag -a $tag -m $tag $commit'
git push --tags origin master
where tag
is set to the desired tag string, and commit
to the commit hash.
The answer by @Phrogz is great, but doesn't work on Windows. Here's how to tag an old commit with the commit's original date using Powershell:
git checkout 9fceb02
$env:GIT_COMMITTER_DATE = git show --format=%aD | Select -First 1
git tag v1.2
git checkout master
참고URL : https://stackoverflow.com/questions/4404172/how-to-tag-an-older-commit-in-git
'your programing' 카테고리의 다른 글
std :: string을 const char * 또는 char *로 변환하는 방법은 무엇입니까? (0) | 2020.09.28 |
---|---|
SQL Server에서 작은 따옴표를 어떻게 이스케이프합니까? (0) | 2020.09.28 |
자바 : 정적 메서드를 사용하는 경우 (0) | 2020.09.28 |
TSQL을 사용하여 데이터베이스의 모든 테이블 목록을 얻으려면 어떻게해야합니까? (0) | 2020.09.28 |
git stash pop과 git stash 적용의 차이점 (0) | 2020.09.28 |