Git远程仓库是Git版本控制系统的一个概念,它是一个存储Git代码的远程服务器。
你可以将本地Git仓库上传到远程仓库,以便与其他人协作开发或备份代码。
远程仓库可以使用第三方平台,如(github、gitlab、gitee)等,这里使用的仓库为gitee
。
地址为:https://gitee.com/
[root@jenkins cangku]# git remote add origin https://gitee.com/yyang2/test_01.git
[root@jenkins cangku]# git push -u origin master
Username for 'https://gitee.com': yyang2
Password for 'https://[email protected]':
Counting objects: 20, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (20/20), 1.80 KiB | 0 bytes/s, done.
Total 20 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yyang2/test_01.git
* [new branch] master -> master
Branch master set up to track remote branch master from origin.
注意账号密码是你创建仓库时自定义的,一定要自己记住。
[root@master-01 ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:MRxAZqBztC5ibEEGPkTPv1sI/BMLe1wG81TawTDsrxo root@master-01
The key's randomart image is:
+---[RSA 2048]----+
|+= oo*++o |
|= oo + o=o. |
| +oooo.o+. |
|. ++. =. o |
|.+.+.o +S |
|o. .* B . |
| . E .. |
| . =. |
| o. |
+----[SHA256]-----+
[root@master-01 ~]# cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDPVwx3MG3oXcRQAx4K5VkPKXR0YiTdxJxGhtNGMWyPoN1j46zUjJtQl0tHsBMQW//NJ0+1+IzM3ReKe7xG8ZvDj9mmtiYu6SkYhPTkB9Qv5uzmu37pQ33MlB3MfthHMAvlu3m5LNZ5LKcz7fnFLBV9OyrgxuFPkgaavm4qIemy5JmthG5K2WXR5MfyNb4jzOTJl3Qxsk3lCDiAU2oXwCtWrx1LbySM8lQZ3hezGvkmauCnn+tFecalYeU/72CjRywX0A7FwHRBMspR4bLkCO+jvTZGB7UswbYC2SvVCAp1qG56KxraIszpmxnYah2Y0ONTo0AvOZENIZvI5IL65nm1 root@master-01
[root@master-01 ~]# mkdir /yu_cangku
[root@master-01 ~]# cd /yu_cangku/
[root@master-01 yu_cangku]# git clone [email protected]:yyang2/test_01.git
正克隆到 'test_01'...
remote: Enumerating objects: 20, done.
remote: Counting objects: 100% (20/20), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 20 (delta 0), reused 0 (delta 0), pack-reused 0
接收对象中: 100% (20/20), done.
[root@master-01 yu_cangku]# ls
test_01
[root@master-01 yu_cangku]# ls test_01/
file1.txt hehe.py
[root@master-01 yu_cangku]# cd test_01/
[root@master-01 test_01]# ls
file1.txt hehe.py
[root@master-01 test_01]# cat file1.txt
hello git
hello world
hello
hello hehehe
[root@master-01 test_01]# echo "hello yuancheng_cangku" >> file1.txt
[root@master-01 test_01]# git add .
[root@master-01 test_01]# git commit -m "远程编辑 -v1"
[root@master-01 test_01]# git config --global user.email "[email protected]"
[root@master-01 test_01]# git config --global user.name "yuancheng"
[root@master-01 test_01]# git push origin master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 326 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To [email protected]:yyang2/test_01.git
0a18968..c5ad2ac master -> master
[root@jenkins cangku]# git pull origin master
Username for 'https://gitee.com': yyang2
Password for 'https://[email protected]':
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://gitee.com/yyang2/test_01
* branch master -> FETCH_HEAD
Updating 0a18968..c5ad2ac
Fast-forward
file1.txt | 1 +
1 file changed, 1 insertion(+)
[root@jenkins cangku]# cat file1.txt
hello git
hello world
hello
hello hehehe
hello yuancheng_cangku
git pull origin master
Git中的标签(tag)主要有以下作用:
1️⃣:标记软件版本:标签最常用的用途就是标记软件版本,类似于在代码的进化过程中某一天突然进行了一次正式的版本发布,或者修复了一个重要的漏洞,或者进行了某些功能的改进等,这些具有里程碑意义的事件发生时,我们可以为其打上一个标签,以方便后续的管理和追踪。
2️⃣:分支过度标签:当Git的分支过多的时候,此时便可以利用标签来对分支进行过度,这样可以减少分支的数量。
3️⃣:轻量级引用:标签其实就是一个指向某个commit的轻量级引用,打了标签后,就可以通过标签来引用这个提交。
[root@jenkins cangku]# git tag v1.0
[root@jenkins cangku]# git tag
v1.0
此时只是将本地仓库做了标签,且为最新内容
[root@jenkins cangku]# git push origin v1.0
Username for 'https://gitee.com': yyang2
Password for 'https://[email protected]':
Total 0 (delta 0), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/yyang2/test_01.git
* [new tag] v1.0 -> v1.0
git tag -a v1.0 [id] -m "v1.0"
[root@jenkins cangku]# git show v1.0
commit c5ad2ac2778758c0c6274427bc9fdaf172fd5779
Author: yuancheng >
Date: Fri Aug 4 17:52:58 2023 +0800
远程 -v1
diff --git a/file1.txt b/file1.txt
index 8a3fe2c..90a5b9e 100644
--- a/file1.txt
+++ b/file1.txt
@@ -2,3 +2,4 @@ hello git
hello world
hello
hello hehehe
+hello yuancheng_cangku
gitignore是一个特殊的文件,用于告诉Git哪些文件或目录不应该被纳入版本控制。在Git仓库中,有些文件或目录可能包含敏感信息、临时文件或者不需要被跟踪的文件,这些文件不应该被包含在Git仓库中。通过使用.gitignore文件,开发者可以告诉Git哪些文件需要被忽略,从而避免将这些文件包含在版本控制中,提高Git仓库的可维护性和安全性。
gitignore文件的主要作用有以下几个方面:
示例:
vim .gitignore
# 忽略所有以“.log”结尾的文件
*.log
# 忽略指定目录下的所有文件和子目录
node_modules/
# 忽略指定文件或目录
my_secret_file.txt
logs/
# 忽略所有以“.swp”结尾的文件
*.swp
# 忽略指定扩展名的文件
*.docx
# 忽略指定文件或目录,以及所有以“.tmp”结尾的文件
temp/
*.tmp
[root@master-01 test_01]# git add .
[root@master-01 test_01]# git commit -m "gitignore"
[root@master-01 test_01]# git push origin master