Hoạt động Tag trong Git



Hoạt động tag cho phép cung cấp tên ý nghĩa cho các phiên bản cụ thể trong repository. Giả sử Tom và Jerry quyết định ghép tag ghi vào code dự án của họ để mà họ sau đó có thể truy cập nó dễ dàng.

Tạo các tag

Hãy cùng chúng tôi ghi tag HEAD hiện tại bằng cách sử dụng lệnh git tag. Tom cung cấp một tên tag với tùy chọn -a và cung cấp một thông tin tag với tùy chọn -m.

tom@CentOS project]$ pwd
/home/tom/top_repo/project[tom@CentOS project]$ git tag -a 'Release_1_0' -m 'Tagged basic string operation code' HEAD

Nếu bạn muốn ghi tag một commit cụ thể, thì khi đó bạn sử dụng ID commit chính xác thay vì điểm trỏ HEAD. Tom sử dụng lệnh sau để push tag vào trong khu vực dỡ bỏ.

[tom@CentOS project]$ git push origin tag Release_1_0

Lệnh trên sẽ tạo ra kết quả sau:

Counting objects: 1, done.
Writing objects: 100% (1/1), 183 bytes, done.
Total 1 (delta 0), reused 0 (delta 0)
To [email protected]:project.git
* [new tag]
Release_1_0 −> Release_1_0

Quan sát các tag

Tom tạo ra các tag. Bây giờ, Jerry có thể quan sát tất cả các tag có sẵn bằng cách sử dụng lệnh git tag với tùy chọn -I.

[jerry@CentOS src]$ pwd
/home/jerry/jerry_repo/project/src[jerry@CentOS src]$ git pull
remote: Counting objects: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From git.server.com:project
* [new tag]
Release_1_0 −> Release_1_0
Current branch master is up to date.[jerry@CentOS src]$ git tag -l
Release_1_0

Jerry sử dụng lệnh git show theo sau bởi tên tag của nó để quan sát chi tiết hơn về tag.

[jerry@CentOS src]$ git show Release_1_0

Lệnh trên sẽ tạo ra kết quả sau:

tag Release_1_0
Tagger: Tom Cat 
Date: Wed Sep 11 13:45:54 2013 +0530Tagged basic string operation code
commit 577647211ed44fe2ae479427a0668a4f12ed71a1
Author: Tom Cat 
Date: Wed Sep 11 10:21:20 2013 +0530Removed executable binarydiff --git a/src/string_operations b/src/string_operations
deleted file mode 100755
index 654004b..0000000
Binary files a/src/string_operations and /dev/null differ

Xóa các tag

Tom sử dụng lệnh sau để xóa các tag từ repository lưu nội bộ cũng như từ xa.

[tom@CentOS project]$ git tag
Release_1_0[tom@CentOS project]$ git tag -d Release_1_0
Deleted tag 'Release_1_0' (was 0f81ff4)
# Remove tag from remote repository.[tom@CentOS project]$ git push origin :Release_1_0
To [email protected]:project.git
- [deleted]
Release_1_0