Git系列文章目录
第一章 Git
文章目录
- Git系列文章目录
- 前言
- 第一章 Git
- 第一节 Git的基本概念及安装
- 1.基本概念
- 1.1 为什么要学习这个工具?
- 1.2 什么是版本控制?(以论文/ppt修改为例)
- 1.3 有什么作用和目的?
- 2.安装
- 2.1 如何用Git对一个目录进行版本控制流程?
- 2.2 在windows中用git去做版本管理
- 第二节 Git的继续学习
- 1.查看本地库状态
- 2.添加暂存区
- 3.提交本地库
- 4.修改文件
- 5.版本回退
- 6.如何创建、切换及删除分支(注:不能删除主分支!!!)
- 7.合并分支(注:仅能在主分支进行合并!!!)
- 第三节 Git的进阶学习
- 1.克隆远端库到本地(git clone 远端链接)
- 2.推送到远端库(git push 远端链接)
- 3.自定义常用命令(Git命令设置别名)
- 总结
前言
本系列文章主要用于记录Git学习问题
如解答有不足之处或问题解决仍待补充,还请大佬多多指教,谢谢!->欢迎评论区留言
第一章 Git
第一节 Git的基本概念及安装
1.基本概念
1.1 为什么要学习这个工具?
- 开源的分布式 -> 文件控制形式
- 版本控制 -> 论文/ppt修改
- 系统/软件 -> 安装软件
1.2 什么是版本控制?(以论文/ppt修改为例)
- 文件(N个)手动管理
- 本地版本控制
- 集中式SVN
- 文件夹123,同学1取走文件1,同学2取走文件2,同学3就无法再读取文件12
- 分布式管理(主要)
- 文件夹123,同学1取走文件123(clone),同学2和同学3依旧可以读取文件123
1.3 有什么作用和目的?
- 会保留并管理之前所有的版本
- 方便代码的版本生成和版本回退及跳转
2.安装
2.1 如何用Git对一个目录进行版本控制流程?
- 步骤一:安装应用(在虚拟机中且ubuntu要有网络)
enshang@enshang:~$ sudo apt-get install git
- 步骤二:新建一个GitStudyFile目录文件(用于Git的学习)
enshang@enshang:~$ mkdir GitStudyFile
- 步骤三:初始化(先进入GitStudyFile目录文件)
- 输入:git init命令
enshang@enshang:~GitStudyFile$ git init
- 结果
Initialized empty Git repository in /home/enshang/GitStudyFile/.git/
- 步骤四:配置姓名和邮箱
- 配置姓名:git config --global user.name “Your Name”
enshang@enshang:~GitStudyFile$ git config --global user.name "GitStudyFile"
- 配置邮箱:git config --global user.email “Your@example.com”
enshang@enshang:~GitStudyFile$ git config --global user.email "GitStudyFile@qq.com"
- 步骤五:新建一个Git1文件
enshang@enshang:~GitStudyFile$ touch Git1
- 步骤六:查看并管理目录下文件的状态(新增的及修改的文件都是红色)
- 输入:git status命令
enshang@enshang:~GitStudyFile$ git status
- 结果
On branch master
No commits yet
Untracked files:(use "git add <file>..." to include in what will be committed)Git1(红色)nothing added to commit but untracked files present (use "git add" to track)
- 步骤七:将指定文件或所有文件加到暂存区(刚新增的及修改的文件会变为绿色)
- 输入:git add 文件名 或 git add.(这里的’.'表示当前文件下所有的文件)
enshang@enshang:~GitStudyFile$ git add Git1
- 结果
enshang@enshang:~GitStudyFile$ git status
On branch master
No commits yet
Changes to be committed:(use "git rm --cached <file>..."to unstage)new file: Git1(绿色)
- 步骤八:生成版本(名字随便起,为了管理)
- 输入:git commit -m “名字”
enshang@enshang:~GitStudyFile$ git commit -m "Git1"
- 结果
[master (root-commit) eseecb9] Git1
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 Git1
- 步骤九:查看版本记录
- 输入:git log命令
enshang@enshang:~GitStudyFile$ git log
- 结果
commit e5eecb90db199d57ccb6105643de86e8aa72edd1 (HEAD -> master)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 3 00:34:00 2023 -0700Git1
- 步骤十:修改Git1文件内容,再次进行步骤六~九
enshang@enshang:~GitStudyFile$ 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: Git1(红色)
no changes added to commit (use "git add" and/or "git commit -a")
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git add Git1
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git status
On branch master
Changes to be committed:(use "git reset HEAD <file>..."to unstage)modified: Git1(绿色)enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git commit -m "Git1_f1"
[master dfiefe8] add f1
1 file changed, 1 insertion(+)
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git log
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb7c5 (HEAD -> master)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 3 00:57:00 2023 -0700Git1_f1commit e5eecb90db199d57ccb6105643de86e8aa72edd1
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 3 00:34:00 2023 -0700Git1
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git status
On branch master
nothing to commit, working tree clean
2.2 在windows中用git去做版本管理
- windows中如何用Git做版本管理: https://git-scm.com/download/win
第二节 Git的继续学习
1.查看本地库状态
- Git查看本地仓库状态(git status)
enshang@enshang:~GitStudyFile$ git status (查看状态)
On branch master
Changes to be comitted:(use "git reset HEAD <file>..."to unstage)new flle: Git1 (绿色:经过git add 加到暂存区的)
Untracked files:(use "git add <file>..."to include in what will be committed)GitStudyFile/ (红色:工作区右半区)
- Git本地仓库各种状态解析
2.添加暂存区
- 查看文件状态
enshang@enshang:~GitStudyFile$ touch Git1
enshang@enshang:~GitStudyFile$ touch Git2 (新建文件)
enshang@enshang:~GitStudyFile$ touch Git3
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git status (查看文件状态)
On branch master
No commits yet
Untracked ftles:(use "git add <file>..." to include in what will be cormitted)Git1Git2 (红色代表-工作区右半区)Git3 nothing added to commit but untracked files present (use "git add" to track)
- 将修改的文件添加到暂存区
- git add 文件名 将某个文件添加到暂存区
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git add Git1 (将Git1添加到暂存区)
enshang@enshang:~GitStudyFile$ git status
On branch master
No commits yet
Changes to be committed:(use "git rm --cached <file>..." to unstage)new file: Git1 (绿了)Untracked files:(use "git add <file>..." to include in what will be committed)Git2Git3 (红色)
- git add . 将所有文件加到暂存区
enshang@enshang:~GitStudyFile$ git add . (将所有的文件添加到暂存区)
enshang@enshang:~GitStudyFile$ git status
On branch master
No commits yet
Changes to be committed:(use "git reset HEAD <file>.." to unstage)new file: Git1new file: Git2 (全绿了)new file: Git3
3.提交本地库
- Git提交到本地库为什么失败?
- 查看状态,必须是暂存区的文件才可以上传版本库
- 必须已经添加了名字和邮箱(配置一次,终生有效)
4.修改文件
- 查看修改的文件
enshang@enshang:~GitStudyFile$ ls
Git1 Git2 Git3
enshang@enshang:~GitStudyFile$ cat Git1 (目前Git1文件里无内容)
enshang@enshang:~GitStudyFile$ vi Git1 (现在往Git1里面添加内容)
enshang@enshang:~GitStudyFile$ cat Git1 (查看一下内容 已添加内容)
Git1
Git1Git1Git1
enshang@enshang:~GitStudyFile$ 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: Git1 (此现象就证明了文件已修改)
no changes added to commit (use "git add" and/or "git commit -a")
- 如何直接在文本界面往Git2文件写入“Git2Git2Git2”
enshang@enshang:~GitStudyFile$ echo "Git2Git2Git2" >> Git2
enshang@enshang:~GitStudyFile$ cat Git2
Git2Git2Git2
- 总结
enshang@enshang:~GitStudyFile$ 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: Git1 (Git1是红色代表现在是工作区右半区 不能上传版本库)
no changes added to commit (use "git add" and/or "git commit -a")
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git add Git1 (将Git1添加到暂存区 等待上传版本库)
enshang@enshang:~GitStudyFile$ git status
On branch master
Changes to be committed:(use "git reset HEAD <file>..."to unstage)modified: Git1 (现在Git1是绿色 代表已经添加到了暂存区)enshang@enshang:~GitStudyFile$ git commit -m "updata | Git1" (将Git1添加到版本库)
[master dfiefe8] updata | Git1
1 file changed, 2 insertions(+)
enshang@enshang:~GitStudyFile$ git log (查看版本库)
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb7c5 (HEAD -> master)
Author: GitStudyFile <GitStudyFile@qq.com> (名字和邮箱)
Date: Mon April 4 00:13:00 2023 -0700updata | Git1 (发现已经添加到了版本库 并被管理起来了)enshang@enshang:~GitStudyFile$
5.版本回退
- 输入:git reset --hard commit命令
enshang@enshang:~GitStudyFile$ git reset --hard dfiefe7
HEAD is now at dfiefe8 Git1_f1
enshang@enshang:~GitStudyFile$
- 查看做过的所有操作的命令
- 输入:git reflog命令
enshang@enshang:~GitStudyFile$ git reflog
63db3a1 (HEAD -> master) HEAD@{0}: reset: moving to dfiefe8
dfiefe8 HEAD@{1}: commit: updata | Git1
63db3a1 (HEAD -> master) HEAD@{2}: commit: updata | Git1
dfiefe7 HEAD@{3}: commit: Git1_f1
e5eecb9 HEAD@{4}:commit (initial): Git1
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git reset --hard dfiefe8
HEAD is now at dfiefe8 updata | Git1
- 总结
enshang@enshang:~GitStudyFile$ cat Git1
Git1
enshang@enshang:~GitStudyFile$ git log (查看版本库,有两个版本)
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb745 (HEAD -> master)
Author: GitStudyFile <GitStudyFile@qq.com> (名字和邮箱)
Date: Mon April 10 19:39:00 2023 -0700Git1 | Git1+Git111commit e4500e904253c49bd18f9598b69668390980155
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 10 19:35:00 2023 -0700Git1 | Git111 enshang@enshang:~GitStudyFile$ git reset --hard e4500e9 (输入第一个版本号)
HEAD is now at dfiefe8 Git1 | Git111
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git log (再次查看版本库,只有一个版本了)
commit e4500e904253c49bd18f9598b69668390980155
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 10 19:35:00 2023 -0700Git1 | Git111 enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ cat Git1_f1 (查看Git_f1发现没有内容了,回退成功)
enshang@enshang:~GitStudyFile$
6.如何创建、切换及删除分支(注:不能删除主分支!!!)
- 输入:git branch命令(创建分支)
enshang@enshang:~GitStudyFile$ git branch
* master
enshang@enshang:~GitStudyFile$ git branch dev (创建分支)
enshang@enshang:~GitStudyFile$ git branch (确认已创建分支)dev
* master
- 输入:git checkout 分支名命令(切换分支)
enshang@enshang:~GitStudyFile$ git checkout dev (切换分支)
Switched to branch 'dev'
enshang@enshang:~GitStudyFile$ git branch (确认已切换分支)
* devmaster
enshang@enshang:~GitStudyFile$ git log (查看版本库)
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb7c5 (HEAD -> dev, master) (表明dev是从master复制过来的)
Author: GitStudyFile <GitStudyFile@qq.com> (名字和邮箱)
Date: Mon April 4 00:13:00 2023 -0700updata | Git1 (发现已经添加到了版本库 并被管理起来了)enshang@enshang:~GitStudyFile$
- 输入:git branch -D 分支名命令(删除分支)
enshang@enshang:~GitStudyFile$ git branch -D dev (删除分支)
Deleted branch dev (was 382fec7).
enshang@enshang:~GitStudyFile$ git branch (确认已删除分支)
* master
- 总结
enshang@enshang:~GitStudyFile$ git branch
* master
enshang@enshang:~GitStudyFile$ git branch dev (创建分支)
enshang@enshang:~GitStudyFile$ git branch (确认已创建分支)dev
* master
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git checkout dev (切换分支)
Switched to branch 'dev'
enshang@enshang:~GitStudyFile$ git branch (确认已切换分支)
* devmaster
enshang@enshang:~GitStudyFile$ git log (查看版本库)
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb7c5 (HEAD -> dev, master) (表明dev是从master复制过来的)
Author: GitStudyFile <GitStudyFile@qq.com> (名字和邮箱)
Date: Mon April 4 00:13:00 2023 -0700updata | Git1 (发现已经添加到了版本库 并被管理起来了)enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git branch -D dev (删除分支,不能删除主分支!!!)
Deleted branch dev (was 382fec7).
enshang@enshang:~GitStudyFile$ git branch (确认已删除分支)
* master
7.合并分支(注:仅能在主分支进行合并!!!)
- 输入:git merge 分支名命令(合并无冲突情况)
enshang@enshang:~GitStudyFile$ git branch
* master
enshang@enshang:~GitStudyFile$ (省略,创建并切换到其他分支下)
enshang@enshang:~GitStudyFile$ git branch (确认已切换分支)
* devmaster
enshang@enshang:~GitStudyFile$ (省略,修改dev分支下的文件并添加到暂存区、版本库等操作...)
enshang@enshang:~GitStudyFile$ git checkout master (必须切换回主分支再合并!!!)
enshang@enshang:~GitStudyFile$ git merge dev
Updating 382foc7..@ab8268
Fast-forward
Git1 | 1+1 file changed, 1 insertion(+)
enshang@enshang:~GitStudyFile$
- 输入:git merge 分支名命令(合并有冲突情况)
- 冲突产生原因:在同一行写了不一样的内容
- 解决冲突方式:用vi打开相关文件,手动删除不需要的内容
enshang@enshang:~GitStudyFile$ git branch
* master
enshang@enshang:~GitStudyFile$ (省略,创建并切换到其他分支下)
enshang@enshang:~GitStudyFile$ git branch (确认已切换分支)
* devmaster
enshang@enshang:~GitStudyFile$ (省略,修改dev分支下的文件并添加到暂存区、版本库等操作...)
enshang@enshang:~GitStudyFile$ git branch (必须切到主分支合并!!!)dev
* master
enshang@enshang:~GitStudyFile$ git merge dev (在主分支中合并dev)
Auto-merging Git1
CONFLICT (content): Merge conflict in Git1
Automatic merge failed; fix conflicts and then cormit the result.
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ cat Git1 (合并之后发现冲突)
<<<<<<< HEAD
Git1
=======
Git111
>>>>>>> dev
enshang@enshang:~GitStudyFile$ vi Git1 (手动去除冲突之后,重新生成版本库就可以了)
enshang@enshang:~GitStudyFile$ cat Git1
Git1
Git111
enshang@enshang:~GitStudyFile$ git add Git1 (将Git1添加到暂存区)
enshang@enshang:~GitStudyFile$ git commit -m "Git1 | Git1+Git111" (生成版本库)
[master 56952e0] Git1 | Git1+Git111
enshang@enshang:~GitStudyFile$ git log (查看本地版本库)
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb745 (HEAD -> master) (表明dev是从master复制过来的)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 10 19:39:00 2023 -0700Git1 | Git1+Git111 commit e4500e904253c49bd18f9598b69668390980155 (dev) (这个是从dev合并过来的分支)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 10 19:35:00 2023 -0700Git1 | Git111 commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb7c5 (origin/master, ortgin/HEAD)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 4 00:13:00 2023 -0700Git1enshang@enshang:~GitStudyFile$
- 总结(合并分支,解决完冲突后提交到版本库)
enshang@enshang:~GitStudyFile$ git branch (查看分支)
* master
enshang@enshang:~GitStudyFile$ git checkout dev (新建分支)
enshang@enshang:~GitStudyFile$ git branch (确认已新建分支)dev
* master
enshang@enshang:~GitStudyFile$ cat Git1
enshang@enshang:~GitStudyFile$ echo "Git1" > Git1 (Git1中添加内容)
enshang@enshang:~GitStudyFile$ cat Git1
Git1
enshang@enshang:~GitStudyFile$ git add Git1
enshang@enshang:~GitStudyFile$ git commit -m "Git1+Git1" (添加到版本库)
[master e8f9705] Git1+Git11 file changed, 1 insertion(+)
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git merge dev
Updating 382foc7..@ab8268
Fast-forward
Git1 | 1+1 file changed, 1 insertion(+)
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git checkout dev (切换分支)
enshang@enshang:~GitStudyFile$ git branch (确认已切换分支)
* devmaster
enshang@enshang:~GitStudyFile$ cat Git1
enshang@enshang:~GitStudyFile$ echo "Git111" > Git1 (Git1中添加内容)
enshang@enshang:~GitStudyFile$ cat Git1
Git111
enshang@enshang:~GitStudyFile$ git add Git1
enshang@enshang:~GitStudyFile$ git commit -m "Git1+Git111" (添加到版本库)
[ma e4500e9] Git1+Git1111 file changed, 1 insertion(+)
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git checkout master
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit.(use "git push" to publish your local cormits)
enshang@enshang:~GitStudyFile$ git branch (必须切到主分支合并!!!)dev
* master
enshang@enshang:~GitStudyFile$ git merge dev (在主分支中合并dev)
Auto-merging Git1
CONFLICT (content): Merge conflict in Git1
Automatic merge failed; fix conflicts and then cormit the result.
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ cat Git1 (合并之后发现冲突)
<<<<<<< HEAD
Git1
=======
Git111
>>>>>>> dev
enshang@enshang:~GitStudyFile$ vi Git1 (手动去除冲突之后,重新生成版本库就可以了)
enshang@enshang:~GitStudyFile$ cat Git1
Git1
Git111
enshang@enshang:~GitStudyFile$ git add Git1 (将Git1添加到暂存区)
enshang@enshang:~GitStudyFile$ git commit -m "Git1 | Git1+Git111" (生成版本库)
[master 56952e0] Git1 | Git1+Git111
enshang@enshang:~GitStudyFile$ git log (查看本地版本库)
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb745 (HEAD -> master) (表明dev是从master复制过来的)
Author: GitStudyFile <GitStudyFile@qq.com> (名字和邮箱)
Date: Mon April 10 19:39:00 2023 -0700Git1 | Git1+Git111 (这个是自己手动生成的)commit e4500e904253c49bd18f9598b69668390980155 (dev) (这个是从dev合并过来的分支)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 10 19:35:00 2023 -0700Git1 | Git111 commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb7c5 (origin/master, ortgin/HEAD)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 4 00:13:00 2023 -0700Git1enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ git branch (查看分支)dev
* master
enshang@enshang:~GitStudyFile$ git branch -D dev (删除dev分支)
Deleted branch dev (was b3cd1f5)
enshang@enshang:~GitStudyFile$ git branch (再次查看分支)
* master (发现work分支已经删除)
enshang@enshang:~GitStudyFile$
第三节 Git的进阶学习
1.克隆远端库到本地(git clone 远端链接)
- 第一步:获取密钥
- 输入:ssh-kevgen - rsa -C "youremail"命令(直接按三次回车即可生成)
enshang@enshang:~GitStudyFile$ ssh-keygen t rsa -c "GitStudyFile@qq.com" (输入获取密钥命令)
Generating public/private rsa key pair.
Enter ftle tn which to save the key (/hore/enshang/.ssh/id rsa):
/home/hu/.ssh/td rsa olready exists.
Overwrite (y/n)? y (确认获取密钥)
Enter passphrase (enpty for no passphrase):
Enter same passphrase again:
Your identificatton has been saved in /home/enshang/.ssh/id rsa.
Your public key has been saved in /home/enshang/.ssh/id_rsa.pub. (密钥保存地址)
The key fingerprint is:
SHA256:@Irh6Mrvs21tahpHXdoixOFn6epdl6l+OPTTS/d6/Gc GitStudyFile@qq.com
The key's randomant inage is:
/* 克隆远端库到本地密钥 */
/* 一个奇怪的图形 */
/* 一个奇怪的图形 */
/* 一个奇怪的图形 */
/* 克隆远端库到本地密钥 */
- 虚拟机输入:cat /home/xxx/.ssh/id_rsa.pub查看公钥[xxx为自己的用户名],将这个公钥添加到git仓库,即可下载clone该仓库的源码文件
enshang@enshang:~GitStudyFile$ cat /home/enshang/.ssh/id_rsa.pub (寻找密钥保存路径)
ssh-rsa AAAAB3NzaC1yC2EAAAADADABAAABAODDPZEtWCFxxlOnSmwnEScjbssD15tr9hDI/Ee94i4pJfxCeulRamosukesnoPerAonnAor+HrnoD602JAZKt8G89Z1jYLivXcrCsHtVnmHGnkCJRXkASMZWnOpT83bLNM+PrEfxF7TVVN/NN7//cCBX5nUorKjCXr/WO9r1PnwIslanwKei+pOdCpR1aVOf6jytuaVlbGs5i+vf4HEuC6qZrmyb7wXed68ISt+gGPF3054KERVtICJ1PLLI6a69ns/7ty0zl2Wbwst9IF4epROsaLxoWmdiKAduNL GitStudyFile@qq.com
enshang@enshang:~GitStudyFile$
- 第二步:打开码云(设置->SSH公钥)->将上方密钥输入并点击确定->输入自己的账号和密码->成功添加SSH公钥
- 第三步:打开虚拟机,克隆代码(输入:git clone gitegiteecon:hhh12321/net -work.git命令)
enshang@enshang:~GitStudyFile$ git clone gitegiteecon:hhh12321/net-work.git
Cloning into 'net-work'...
remote: Enurerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 10 (delta 2), reused 0 (delta 0), pack-reused 0
Recetving objects: 100% (10/10), done.
Resolving deltas: 100% (2/2), done.
enshang@enshang:~GitStudyFile$
enshang@enshang:~GitStudyFile$ ls
net-work
enshang@enshang:~GitStudyFile$ cd net-work/
enshang@enshang:~GitStudyFile/net-work$ ls
Git1 Git2 Git3
enshang@enshang:~GitStudyFile/net-work$
- 第四步:将密钥加载到码云,即可克隆或上传(一般由领导管理)
2.推送到远端库(git push 远端链接)
- 第一步:查看码云中的远端库文件目录
- 第二步:将远端库克隆下来之后添加文件之后推送到远端(输入:git push 远端链接命令)
enshang@enshang:~GitStudyFile/net-work$ git push gitegitee.com:hhh12321/net-work.gtt
Counting objects: 2. done.
Delta compresston using up to 2 threads.
Compressing objects: 100% (2/2) done.
Writing objects: 100% (2/2), 216 bytes | 216.00 KiB/s, done.
Total 2 (delta 1), reused 0(delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To gttee.com:hhh12321/net-work.git434e42a..113a534 master -> master
enshang@enshang:~GitStudyFile/net-work$
- 第三步:查看本地库推送到远端库之后的状态
3.自定义常用命令(Git命令设置别名)
enshang@enshang:~$ sudo cat ~/.gitconfig (查看git配置信息)
[user]name = GitStudyFileemail = GitStudyFile@qq.com
enshang@enshang:~$
enshang@enshang:~$ sudo vi ~/.gitconfig (添加别名信息)
enshang@enshang:~$ sudo cat ~/.gitconfig (查看添加的内容)
[user]name = GitStudyFileemail = GitStudyFile@qq.com
[alias]ls = log (此处是将git log 起了 git ls别名,两者作用一样)
enshang@enshang:~$ cd GitStudyFile/net-work/
enshang@enshang:~GitStudyFile/net-work$ git ls (验证是否别名命令是否生效?等同于git log命令查看本地版本库,已生效)
commit dfiefe80fe1daf7c36daa0f1ed0e490ab52eb7c5 (HEAD -> master)
Author: GitStudyFile <GitStudyFile@qq.com>
Date: Mon April 4 00:13:00 2023 -0700Git1enshang@enshang:~GitStudyFile/net-work$
总结
本章为Git系列文章 第一章:Git