Git命令行2

一、拉取项目

1、进入文件夹

cd /Users/cr/Desktop/git

 

2、查看远程仓库地址

 

 3、执行如下代码

#拉取代码
crdeMacBook-Pro:git cr$ git clone http://gitlab.xxx.xxx/root/gitteset.git
Cloning into 'gitteset'...
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.

#进入文件夹
crdeMacBook-Pro:git cr$ cd gitteset

#查看
crdeMacBook-Pro:gitteset cr$ ll
total 16
drwxr-xr-x@  5 cr  staff  160  2 15 09:55 ./
drwxr-xr-x@  4 cr  staff  128  2 15 09:55 ../
drwxr-xr-x@ 12 cr  staff  384  2 15 09:55 .git/
-rw-r--r--   1 cr  staff    4  2 15 09:55 README.md
-rw-r--r--   1 cr  staff    5  2 15 09:55 test.txt

#新建文件
crdeMacBook-Pro:gitteset cr$ touch test1.txt

#添加所有文件
crdeMacBook-Pro:gitteset cr$ git add .

#使用"git commit -m <提交日志信息>"命令将代码提交到本地仓库
crdeMacBook-Pro:gitteset cr$ git commit -m "add test1.txt"
[master 9f1b4b1] add test1.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 test1.txt

#提交代码到远程 crdeMacBook
-Pro:gitteset cr$ git push Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 12 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 302 bytes | 302.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://gitlab.xuanqi.co/root/gitteset.git f5772b9..9f1b4b1 master -> master crdeMacBook-Pro:gitteset cr$

4、远程仓库刷新后,已有新增文件

 

5、修改文件内容后提交

git add .
git commit -m "test1.txt update"
git push

 

 二、分支管理

1、添加一个分支

 

 下面的界面中输入分支的名字,另外你可以选择Create from的来源,这会决定从哪个分支进行创建,这里用了默认的master主干目录,点击Create branch按钮即可创建分支。

看项目的分支目录,可以看到,除了默认的master主干目录,现在多了一个mybranch分支目录,可以点进去查看一下详细信息,该目录的创建源是主干目录,目录中的内容和master主干目录完全一致。

 

2、切换分支

首先需要执行"git pull"命令将变更内容拉下来,目前本地仓库是master主分支的,现在我们要切换到mybranch分支,使用的是"git checkout 要切换的分支名"命令

#拉取所有
crdeMacBook-Pro:gitteset cr$ git pull
From http://gitlab.xuanqi.co/root/gitteset
 * [new branch]      mybranch   -> origin/mybranch
Already up to date.

#切换分支
crdeMacBook-Pro:gitteset cr$ git checkout mybranch
Branch 'mybranch' set up to track remote branch 'mybranch' from 'origin'.
Switched to a new branch 'mybranch'
crdeMacBook-Pro:gitteset cr$ 

3、修改内容,并提交

#修改内容
crdeMacBook-Pro:gitteset cr$ vi test1.txt

#查看修改的内容
crdeMacBook-Pro:gitteset cr$ cat test1.txt
test 
mybranch

#添加修改
crdeMacBook-Pro:gitteset cr$ git add .

#提交本地
crdeMacBook-Pro:gitteset cr$ git commit -m "mybranch update"
[mybranch 12e7ab5] mybranch update
 1 file changed, 1 insertion(+)

#提交到远程仓库
crdeMacBook-Pro:gitteset cr$ git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 12 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 266 bytes | 266.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0)
remote: 
remote: To create a merge request for mybranch, visit:
remote:   http://gitlab.xuanqi.co/root/gitteset/-/merge_requests/new?merge_request%5Bsource_branch%5D=mybranch
remote: 
To http://gitlab.xuanqi.co/root/gitteset.git
   09a7fa7..12e7ab5  mybranch -> mybranch
crdeMacBook-Pro:gitteset cr$ 

4、查看主、分支内容

 

     

 

 5、合并分支

#查看分支的内容
crdeMacBook-Pro:gitteset cr$ cat test1.txt
test 
mybranch

#切换到主分支
crdeMacBook-Pro:gitteset cr$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.

#查看内容 刚刚的改动都不见了
crdeMacBook-Pro:gitteset cr$ cat test1.txt
test 
crdeMacBook-Pro:gitteset cr$

执行合并

#合并分支到当前主分支
crdeMacBook-Pro:gitteset cr$ git merge mybranch
Updating 09a7fa7..12e7ab5
Fast-forward
 test1.txt | 1 +
 1 file changed, 1 insertion(+)


#查看内容与分支相同
crdeMacBook-Pro:gitteset cr$ cat test1.txt
test 
mybranch
crdeMacBook-Pro:gitteset cr$ 

 三、设置提交代码时的用户信息

#显示
git config user.name
#设置
git config --global user.name 'xxx'

 

 

 

 

 

 

 

 

posted @ 2021-02-15 10:48  桥头堡洗脚城  阅读(49)  评论(0编辑  收藏  举报