[root@LAPTOP-1UJN7PP7 git-learn]# git log --pretty=oneline 196ad7fafa50d6558e2c4da42344e7ff292d1447 first commit
可以使用git reflog查看操作记录:
1 2 3 4 5
[root@LAPTOP-1UJN7PP7 git-learn]# git reflog 196ad7f HEAD@{0}: reset: moving to HEAD^ 5e3f973 HEAD@{1}: commit: second commit 196ad7f HEAD@{2}: commit (initial): first commit
可以查看到第二次提交的commit id,从而再次变更为第二次版本:
1 2 3
[root@LAPTOP-1UJN7PP7 git-learn]# git reset --hard 5e3f973 HEAD is now at 5e3f973 second commit
2. 工作区与暂存区
文件所在地方为工作区,当文件被修改后,用git status查看:
1 2 3 4 5 6 7 8 9 10
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.md # no changes added to commit (use "git add" and/or "git commit -a")
显示文件已被修改但是没有add和commit
add文件后,文件来到暂存区,用git status查看:
1 2 3 4 5 6 7 8
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README.md #
显示文件没有commit
commit文件后,文件来到版本库,用git status查看:
1 2 3 4
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master nothing to commit, working directory clean
3.管理修改
Git比其他版本控制系统设计得优秀,因为Git跟踪并管理的是修改,而非文件
修改文件:
1
[root@LAPTOP-1UJN7PP7 git-learn]# echo "This is a new line" >> README.md
查看修改:
1 2 3
[root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This is third commit This is a new line
添加到暂存区:
1 2 3 4 5 6 7 8 9
[root@LAPTOP-1UJN7PP7 git-learn]# git add README.md [root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README.md #
再次修改文件:
1 2
[root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This is third commit
此时我们提交修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Add a new line" [master 6e2db9d] Add a new line Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
可以看到提交的是插入了一行,也就是上一次修改
我们看一下文件状态:
1 2 3 4 5 6 7 8 9
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.md #vi no changes added to commit (use "git add" and/or "git commit -a")
提交后,用git diff HEAD -- readme.txt命令可以查看工作区和版本库里面最新版本的区别:
1 2 3 4 5 6 7 8
[root@LAPTOP-1UJN7PP7 git-learn]# git diff HEAD README.md diff --git a/README.md b/README.md index 28bc83d..62c3f45 100644 --- a/README.md +++ b/README.md @@ -1,2 +1 @@ This is third commit -This is a new line
可见,第二次修改确实没有被提交
4.撤销修改
4.1.修改但未提交
错误的修改文件但未提交:
1 2 3 4 5
[root@LAPTOP-1UJN7PP7 git-learn]# echo "This is an error" >> README.md [root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is an error
使用git status查看:
1 2 3 4 5 6 7 8 9 10
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.md # no changes added to commit (use "git add" and/or "git commit -a")
Git提示可以use "git checkout -- <file>..." to discard changes in working directory,即使用git checkout -- <file>来丢弃修改:
1 2 3 4
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout -- README.md [root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file
[root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is an error [root@LAPTOP-1UJN7PP7 git-learn]# git add README.md [root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: README.md #
Git提示use "git reset HEAD <file>..." to unstage,即使用git reset HEAD <file>来丢弃存储区修改:
1 2 3 4
[root@LAPTOP-1UJN7PP7 git-learn]# git reset HEAD README.md Unstaged changes after reset: M README.md
查看状态:
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README.md # no changes added to commit (use "git add" and/or "git commit -a") [root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is an error
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout -- README.md [root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file [root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master nothing to commit, working directory clean
4.3.修改已提交
回退上一个版本:
1 2 3
[root@LAPTOP-1UJN7PP7 git-learn]# git reset --hard HEAD^ HEAD is now at 196ad7f first commit
5.删除文件
删除工作区文件:
1 2
[root@LAPTOP-1UJN7PP7 git-learn]# rm -rf test.txt
查看状态:
1 2 3 4 5 6 7 8 9 10
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # Changes not staged for commit: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: test.txt # no changes added to commit (use "git add" and/or "git commit -a")
Git知道我们删除了文件并提示use "git add/rm <file>..." to update what will be committed,即我们可以使用git add <file>或者git rm <file>来删除版本库中的文件:
[root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Delete a file" [master af52d1c] Delete a dile Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout -b feature Switched to a new branch 'feature' [root@LAPTOP-1UJN7PP7 git-learn]# ls dev.txt README.md test.txt [root@LAPTOP-1UJN7PP7 git-learn]# echo "This is feature line" >> README.md [root@LAPTOP-1UJN7PP7 git-learn]# git add README.md [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Add a line in feature branch" [feature 4ecad70] Add a line in feature branch Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+) [root@LAPTOP-1UJN7PP7 git-learn]# git checkout master Switched to branch 'master' [root@LAPTOP-1UJN7PP7 git-learn]# echo "This is master line" >> README.md [root@LAPTOP-1UJN7PP7 git-learn]# git add README.md [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Add a line in master branch" [master 9a22c75] Add a line in master branch Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
我们尝试合并:
1 2 3 4 5
[root@LAPTOP-1UJN7PP7 git-learn]# git merge feature Auto-merging README.md CONFLICT (content): Merge conflict in README.md Automatic merge failed; fix conflicts and then commit the result.
发生冲突,无法自动合并
此时我们查看状态:
1 2 3 4 5 6 7 8 9 10 11 12
[root@LAPTOP-1UJN7PP7 git-learn]# git status # On branch master # You have unmerged paths. # (fix conflicts and run "git commit") # # Unmerged paths: # (use "git add <file>..." to mark resolution) # # both modified: README.md # no changes added to commit (use "git add" and/or "git commit -a")
也提示存在冲突,并且提示fix conflicts and run "git commit",即修改文件后使用git commit来解决冲突
我们查看文件:
1 2 3 4 5 6 7 8 9
[root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is dev line <<<<<<< HEAD This is master line ======= This is feature line >>>>>>> feature
Git用<<<<<<<,=======,>>>>>>>标记出不同分支的内容,我们修改如下后保存:
1 2 3 4 5
[root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is dev line This is master and feature line
提交修改:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@LAPTOP-1UJN7PP7 git-learn]# git add README.md [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "conflict fixed" [master e52bbb2] conflict fixed Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
可以看到冲突解决了
用带参数的git log可以看到分支的合并情况:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@LAPTOP-1UJN7PP7 git-learn]# git log --graph --pretty=oneline --abbrev-commit * e52bbb2 conflict fixed |\ | * 4ecad70 Add a line in feature branch * | 9a22c75 Add a line in master branch |/ * 4dfabbc dev branch first commit * e9442cf Add test.txt * c2f0b57 Modified a file * 6e2db9d Add a new line * 061be34 third commit * 5e3f973 second commit * 196ad7f first commit
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout -b dev Switched to a new branch 'dev' [root@LAPTOP-1UJN7PP7 git-learn]# echo "This is a new line" >>dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git add dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Add a line in dev.txt" [dev 9f34d0d] Add a line in dev.txt Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout -b dev Switched to a new branch 'dev' [root@LAPTOP-1UJN7PP7 git-learn]# echo "This is second new line" >>dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git add dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Add a line in dev.txt" [dev 1e70bdc] Add a line in dev.txt Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+) [root@LAPTOP-1UJN7PP7 git-learn]# git checkout master Switched to branch 'master' [root@LAPTOP-1UJN7PP7 git-learn]# git merge dev --no-ff Merge made by the 'recursive' strategy. dev.txt | 1 + 1 file changed, 1 insertion(+) [root@LAPTOP-1UJN7PP7 git-learn]# git log --graph --pretty=oneline --abbrev-commit * afca374 Merge branch 'dev' |\ | * 1e70bdc Add a line in dev.txt |/ * 9f34d0d Add a line in dev.txt * e52bbb2 conflict fixed |\ | * 4ecad70 Add a line in feature branch * | 9a22c75 Add a line in master branch |/ * 4dfabbc dev branch first commit * e9442cf Add test.txt * c2f0b57 Modified a file * 6e2db9d Add a new line * 061be34 third commit * 5e3f973 second commit * 196ad7f first commit
[root@LAPTOP-1UJN7PP7 git-learn]# git stash Saved working directory and index state WIP on dev: afca374 Merge branch 'dev' HEAD is now at afca374 Merge branch 'dev'
切换到master分支并且创建BUG修复分支:
1 2 3 4 5
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout master Switched to branch 'master' [root@LAPTOP-1UJN7PP7 git-learn]# git checkout -b bug-fixed Switched to a new branch 'bug-fixed'
[root@LAPTOP-1UJN7PP7 git-learn]# echo "fix bug" >> README.md [root@LAPTOP-1UJN7PP7 git-learn]# git add README.md [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "bug fixed" [bug-fixed b5abcdd] bug fixed Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
[root@LAPTOP-1UJN7PP7 git-learn]# git branch dev * master [root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is dev line This is master and feature line fix bug
可以看到BUG在master上已经修复
可是dev分支呢?
1 2 3 4 5 6 7
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout dev Switched to branch 'dev' [root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is dev line This is master and feature line
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout dev Switched to branch 'dev' [root@LAPTOP-1UJN7PP7 git-learn]# git cherry-pick b5abcdd [dev 7429c57] bug fixed Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
[root@LAPTOP-1UJN7PP7 git-learn]# cat README.md This git test file This is dev line This is master and feature line fix bug [root@LAPTOP-1UJN7PP7 git-learn]# git log --graph * commit 7429c57090cf3a146ec6f64ff60658922e08b235 | Author: root <root@LAPTOP-1UJN7PP7.localdomain> | Date: Tue Mar 8 12:47:40 2022 +0800 | | bug fixed | * commit afca374ed3030782154c0b289378286111006643 |\ Merge: 9f34d0d 1e70bdc | | Author: root <root@LAPTOP-1UJN7PP7.localdomain> | | Date: Tue Mar 8 12:24:00 2022 +0800 | | | | Merge branch 'dev' | | | * commit 1e70bdc1dee854f049b18e11e0b0971c30fc34e6 |/ Author: root <root@LAPTOP-1UJN7PP7.localdomain> | Date: Tue Mar 8 12:23:09 2022 +0800 | | Add a line in dev.txt |
可以看到dev上的BUG确实修复了并且在dev上有了一次新的commit
最后,恢复工作区:
1 2 3 4 5 6 7 8 9 10 11
[root@LAPTOP-1UJN7PP7 git-learn]# git stash pop # On branch dev # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: dev.txt # no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (18f91d7c6f57e8b4b58d6172419a814a61b0d07e)
[root@LAPTOP-1UJN7PP7 git-learn]# git branch -d dev error: The branch 'dev' is not fully merged. If you are sure you want to delete it, run 'git branch -D dev'. [root@LAPTOP-1UJN7PP7 git-learn]# git branch -D dev Deleted branch dev (was 7429c57).
[root@LAPTOP-1UJN7PP7 git-learn]# git checkout -b dev origin/dev Branch dev set up to track remote branch dev from origin. Switched to a new branch 'dev'
[root@LAPTOP-1UJN7PP7 git-learn]# echo "This is a new line" >> dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git add dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Add a line" [dev 29f398e] Add a line Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
[root@LAPTOP-1UJN7PP7 git-learn]# echo "This is a new line" >> dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git add dev.txt [root@LAPTOP-1UJN7PP7 git-learn]# git commit -m "Add a line" [dev 2a494fc] Add a line Committer: root <root@LAPTOP-1UJN7PP7.localdomain> Your name and email address were configured automatically based on your username and hostname. Please check that they are accurate. You can suppress this message by setting them explicitly:
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+) [root@LAPTOP-1UJN7PP7 git-learn]# git push origin dev To git@github.com:zhnny/git-learn.git ! [rejected] dev -> dev (fetch first) error: failed to push some refs to 'git@github.com:zhnny/git-learn.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first merge the remote changes (e.g., hint: 'git pull') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details.
可以看到后面这个push失败,Git提示我们先pull下来,merge后再推送
pull远程仓库:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@LAPTOP-1UJN7PP7 git-learn]# git pull remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0 Unpacking objects: 100% (3/3), done. From github.com:zhnny/git-learn a7ae8d2..29f398e dev -> origin/dev There is no tracking information for the current branch. Please specify which branch you want to merge with. See git-pull(1) for details
git pull <remote> <branch>
If you wish to set tracking information for this branch you can do so with:
[root@LAPTOP-1UJN7PP7 git-learn]# git branch --set-upstream-to=origin/dev dev Branch dev set up to track remote branch dev from origin.
再次pull:
1 2 3
[root@LAPTOP-1UJN7PP7 git-learn]# git pull Merge made by the 'recursive' strategy.
merge后再次push:
1 2 3 4 5 6 7 8 9 10
[root@LAPTOP-1UJN7PP7 git-learn]# git push origin dev Counting objects: 2, done. Delta compression using up to 12 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 353 bytes | 0 bytes/s, done. Total 2 (delta 1), reused 0 (delta 0) remote: Resolving deltas: 100% (1/1), done. To git@github.com:zhnny/git-learn.git 29f398e..3eda6cf dev -> dev
12.Rebase操作
rebase操作:
rebase操作可以把本地未push的分叉提交历史整理成直线
rebase的目的是使得我们在查看历史提交的变化时更容易,因为分叉的提交需要三方对比
rebase前:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
[root@LAPTOP-1UJN7PP7 git-learn]# git log --graph --pretty=oneline * b3c1899f42d1364eee047c3ec22ffb7b18912d67 merge conflict |\ | * 7d9e9e2375785c7d594da445823bc2ceffcb2137 Add a new line | * 1ed7903f52d52ce675bdedeb29b41f8648aaefbc Add a new line | * 3bc7183e800263d908d1b7701c9b15860e58beca Add a new line | * 905a799a93d51d11a588e2493bdc23765b9b3fde merge confict | |\ | * | aa43bf9c412070c05227e475a5c1f7d633f208c1 Add the fifth line * | | 6fd7b915a404dbea8dea256c4f5f6e8e4376e9f5 Add a new line | |/ |/| * | cda61afd2f6b2c7dcad3db5abe8e1f8304354fbe Add the forth line * | 44e789020405f50780964136663edd4701bb39d7 Add the third line |/ * 74a80dc3c466574717ccfffbf341609259e111a6 Add the second new line * e85a234700ebf67aa23434d9bde59b18845eadee Add a new line * 1a20b8eba002fcd70bbb6ca039dc41fe66ab1d81 Add a line
rebase:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[root@LAPTOP-1UJN7PP7 git-learn]# git rebase First, rewinding head to replay your work on top of it... Applying: Add a new line Using index info to reconstruct a base tree... M dev.txt Falling back to patching base and 3-way merge... Auto-merging dev.txt CONFLICT (content): Merge conflict in dev.txt Failed to merge in the changes. Patch failed at 0001 Add a new line The copy of the patch that failed is found in: /root/clone/git-learn/.git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".
[root@LAPTOP-1UJN7PP7 git-learn]# git rebase --continue Applying: Add a new line
rebase后:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@LAPTOP-1UJN7PP7 git-learn]# git log --graph --pretty=oneline * 9119f8fb6a62595fa70456132aa7329aee9630e0 Add a new line * 7d9e9e2375785c7d594da445823bc2ceffcb2137 Add a new line * 1ed7903f52d52ce675bdedeb29b41f8648aaefbc Add a new line * 3bc7183e800263d908d1b7701c9b15860e58beca Add a new line * 905a799a93d51d11a588e2493bdc23765b9b3fde merge confict |\ | * cda61afd2f6b2c7dcad3db5abe8e1f8304354fbe Add the forth line | * 44e789020405f50780964136663edd4701bb39d7 Add the third line * | aa43bf9c412070c05227e475a5c1f7d633f208c1 Add the fifth line |/ * 74a80dc3c466574717ccfffbf341609259e111a6 Add the second new line * e85a234700ebf67aa23434d9bde59b18845eadee Add a new line * 1a20b8eba002fcd70bbb6ca039dc41fe66ab1d81 Add a line
[root@LAPTOP-1UJN7PP7 git-learn]# git log --graph --pretty=oneline * b5abcdd2cb9294a98874cd3ab78a212566728dec bug fixed * afca374ed3030782154c0b289378286111006643 Merge branch 'dev' |\ | * 1e70bdc1dee854f049b18e11e0b0971c30fc34e6 Add a line in dev.txt |/ * 9f34d0def7a71384b3528f9a1056fa1badc9d0c2 Add a line in dev.txt * e52bbb2ec0fd79188b47060ebe5ee515c14ac557 conflict fixed |\ | * 4ecad70e9719d9d5d2e95ca1ef2fc12c7016b4b4 Add a line in feature branch * | 9a22c75daf397a63a8598094e209f078e0a8a1f7 Add a line in master branch |/ * 4dfabbce1de291335759960028913e31491ccfce dev branch first commit * e9442cfef62eada2943e45ac4c2782f2bc54b9b4 Add test.txt * c2f0b571b6b84becc27440e6670b69b0a9b035a7 Modified a file * 6e2db9d63f9984e2233a6c3c972b00489f315074 Add a new line * 061be34209d57299ffe96616f82008ee4655eea0 third commit * 5e3f973bf0248775995e6197cb999c874abc3859 second commit * 196ad7fafa50d6558e2c4da42344e7ff292d1447 first commit [root@LAPTOP-1UJN7PP7 git-learn]# git tag v0.9 afca
再次查看标签:
1 2 3 4
[root@LAPTOP-1UJN7PP7 git-learn]# git tag v0.9 v1.0
注意,标签不是按时间顺序列出,而是按字母排序的
可以用git show <tagname>查看标签信息:
1 2 3 4 5 6 7 8 9
[root@LAPTOP-1UJN7PP7 git-learn]# git show v0.9 commit afca374ed3030782154c0b289378286111006643 Merge: 9f34d0d 1e70bdc Author: root <root@LAPTOP-1UJN7PP7.localdomain> Date: Tue Mar 8 12:24:00 2022 +0800
Merge branch 'dev'
还可以创建带有说明的标签,用-a指定标签名,-m指定说明文字:
1 2
[root@LAPTOP-1UJN7PP7 git-learn]# git tag -a v0.1 196a -m "version 0.1 released"