远程仓库
新建仓库
…or create a new repository on the command line
echo "# test-library" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/zhaoziyan98/test-library.git
git push -u origin main
推送现有仓库
…or push an existing repository from the command line
git remote add origin https://github.com/zhaoziyan98/test-library.git
git branch -M main
git push -u origin main
单个远程库操作:
# 在本地库上使用命令git remote add把它和Gitee的远程库关联:
## 说明本地库已经关联了一个名叫origin的远程库
$ git remote add origin git@gitee.com:zhaoziyan98/test-library.git
error: remote origin already exists.
# 查看远程库信息
$ git remote -v
origin https://github.com/zhaoziyan98/test-library.git (fetch)
origin https://github.com/zhaoziyan98/test-library.git (push)
# 删除已有的github远程库
$ git remote rm origin
# 再次关联gitee
$ git remote add origin git@gitee.com:zhaoziyan98/test-library.git
多个远程库操作:
# 关联GitHub远程库
$ git remote add github-test git@github.com:zhaoziyan98/test-library.git
# 关联gitee远程库
$ git remote add gitee-test git@gitee.com:zhaoziyan98/test-library.git
# 查看关联库信息
$ git remote -v
gitee-test git@gitee.com:zhaoziyan98/test-library.git (fetch)
gitee-test git@gitee.com:zhaoziyan98/test-library.git (push)
github-test git@github.com:zhaoziyan98/test-library.git (fetch)
github-test git@github.com:zhaoziyan98/test-library.git (push)
# 提交至分支
$ git push github-test master
The authenticity of host 'github.com (13.250.177.223)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'master' on GitHub by visiting:
remote: https://github.com/zhaoziyan98/test-library/pull/new/master
remote:
To github.com:zhaoziyan98/test-library.git
* [new branch] master -> master
tips:使用已有的仓库clone到本地,并进行操作
# git 拉取远端仓库
$ git clone git@gitee.com:zhaoziyan98/test-library.git
Cloning into 'test-library'...
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (20/20), done.
Receiving objects: 100% (37/37), 4.04 KiB | 1.34 MiB/s, done.
remote: Total 37 (delta 1), reused 0 (delta 0), pack-reused 0
Resolving deltas: 100% (1/1), done.
# 进入目录
$ cd test-library/
$ git branch
* master
# 创建分支
$ git branch zhaoziyan
# 切换分支,在分支上进行操作
$ git checkout zhaoziyan
Switched to branch 'zhaoziyan'
$ git add 1.txt
$ git commit -m "zhaoziyan"
[zhaoziyan 0af8f0f] zhaoziyan
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 1.txt
Administrator@ZLPC-20191204LF MINGW64 /f/GitRepository/test-library (zhaoziyan)
# 推到远程仓库
$ git push origin zhaoziyan
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 291 bytes | 291.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
remote: Create a pull request for 'zhaoziyan' on Gitee by visiting:
remote: https://gitee.com/zhaoziyan98/test-library/pull/new/zhaoziyan98:zhaoziyan...zhaoziyan98:master
To gitee.com:zhaoziyan98/test-library.git
* [new branch] zhaoziyan -> zhaoziyan
git标签
Git的标签虽然是版本库的快照,但其实它就是指向某个commit的指针(跟分支很像对不对?但是分支可以移动,标签不能移动),所以,创建和删除标签都是瞬间完成的。
创建标签:
# 查看标签
## 标签不是按时间顺序列出,而是按字母排序的
$ git tag
v1.0
# 创建标签
## 默认标签是打在最新提交的commit上的
$ git tag v1.0
# 指定标签信息
$ git tag -a v0.2 -m "标签信息" 0af8f0f8f45a0a2a18e910e9f37e91b358b5b63a
# 根据commit id 进行打标签
$ git log --pretty=oneline
b9125adbe9329c2610d0fc48e898aab392bf5774 (HEAD -> test2, tag: v1.0) Merge branch 'test' of gitee.com:zhaoziyan98/test-library into test2
8071992a2aaf9e4ea6cf6a94904d562a06931113 (origin/test) sds
9de14e0c739e712f9983b65c19d4bcf001bcde0e Merge branch 'test2' of gitee.com:zhaoziyan98/test-library into test2
fba74c9a78d7ca7f647a16f0e2d36c249d1ff09b (origin/test2) add sadasdasdas.
0af8f0f8f45a0a2a18e910e9f37e91b358b5b63a (origin/zhaoziyan, zhaoziyan, test) zhaoziyan
de94f789598f0757b9efca5ae21e00f50ae17812 (origin/master, origin/HEAD, master) Initial commit
176fc0fc34f5ce9ea26b2abb2bd9095102005fe3 Initial commit
$ git tag v0.1 0af8f0f8f45a0a2a18e910e9f37e91b358b5b63a
$ git tag
v0.1
v1.0
# 查看标签信息
$ git show v1.0
commit b9125adbe9329c2610d0fc48e898aab392bf5774 (HEAD -> test2, tag: v1.0)
Merge: 9de14e0 8071992
Author: zhaoziyan <zhaoziyan@qq.com>
Date: Tue Jun 1 16:34:51 2021 +0800
Merge branch 'test' of gitee.com:zhaoziyan98/test-library into test2
$ git show v0.2
tag v0.2
Tagger: zhaoziyan <zhaoziyan@qq.com>
Date: Tue Jun 1 18:04:50 2021 +0800
标签信息
commit 0af8f0f8f45a0a2a18e910e9f37e91b358b5b63a (tag: v0.2, tag: v0.1, origin/zhaoziyan, zhaoziyan, test)
Author: zhaoziyan <zhaoziyan@qq.com>
Date: Tue Jun 1 16:30:54 2021 +0800
zhaoziyan
diff --git a/1.txt b/1.txt
new file mode 100644
index 0000000..e69de29
操作标签:
# 删除标签
## 因为创建的标签都只存储在本地,不会自动推送到远程。所以,打错的标签可以在本地安全删除。
$ git tag -d v0.1
Deleted tag 'v0.1' (was 0af8f0f)
# 推送某个标签到远程仓库
$ git push origin v0.2
Enumerating objects: 1, done.
Counting objects: 100% (1/1), done.
Writing objects: 100% (1/1), 170 bytes | 170.00 KiB/s, done.
Total 1 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:zhaoziyan98/test-library.git
* [new tag] v0.2 -> v0.2
# 一次性推送全部尚未推送到远程的本地标签
$ git push origin --tags
Enumerating objects: 7, done.
Counting objects: 100% (7/7), done.
Delta compression using up to 8 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 656 bytes | 656.00 KiB/s, done.
Total 4 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:zhaoziyan98/test-library.git
* [new tag] v1.0 -> v1.0
# 删除远程标签
## 先删除本地标签
$ git tag -d v0.1
Deleted tag 'v0.1' (was 0af8f0f)
## 从远程删除
$ git push origin :refs/tags/v0.2
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:zhaoziyan98/test-library.git
- [deleted] v0.2