|NO.Z.00006|——————————|^^ 配置 ^^|——|CI/CD&Git配置.V05|——|Git项目交互|

一、本地项目与Git-server之间交互
### --- 如果你没有最新的代码,希望从头开始
~~~     clone版本库到gitclient
~~~     这里是项目的地址(可从项目主页复制),将远程服务器的内容完全复制过来

[root@server12 ~]# git clone git@XXX.git                       
~~~     修改项目文件;push到版本包

[root@server12 ~]# cd BGBInspector_V01                              // clone 之后进入该项目的文件夹
[root@server12 ~]# touch README.md                                 // 新建readme文件
[root@server12 ~]# git add README.md                                // 将新的文件添加到git的暂存区
[root@server12 ~]# git commit -mIts noteadd a readme file’    // 将暂存区的文件提交到某一个版本保存下来,并加上注释
[root@server12 ~]# git push -u origin master                        // 将本地的更改提交到远程服务器
### --- 如果你已经有一个新版代码,希望直接把本地的代码替换到远程服务器
~~~     push项目到版本库

[root@server12 ~]# cd existing_folder                                   // 进入代码存在的文件夹,或者直接在该文件夹打开
[root@server12 ~]# git init                                             // 初始化
[root@server12 ~]# git remote add origin git@master:/git-test/shell.git // 添加远程项目"shell"库的地址(可从项目主页复制) ,前提是事先需要先在git远程服务器上创建相应的裸库"shell"
[root@server12 ~]# git add .                                            // 添加该文件夹中所有的文件到git的暂存区
[root@server12 ~]# git commit -m ‘note’                               // 提交所有代码到本机的版本库
[root@server12 ~]# git push -u origin master                            // 将本地的更改提交到远程服务器
### --- Git.push项目说明

~~~     git 中 clone过来的时候,git 不会对比本地和服务器的文件,也就不会有冲突,
~~~     建议确定完全覆盖本地的时候用 clone,不确定会不会有冲突的时候用 git pull,
~~~     将远程服务器的代码download下来
二、Git.pull项目:git pull=git fetch+git merge
### --- 本地代码
~~~     本地代码内容如下:

[root@server12 shell]# cat mem.sh
free -m | awk 'NR==2{print $4}'
echo hello
echo ni hao
### --- git-server代码如下
~~~     远程Git服务器代码内容如下:

[root@server12 shell]# cat mem.sh
free -m | awk 'NR==2{print $4}'
echo hello
echo ni hao
echo ha ha
### --- 本地client做fetch操作
~~~     本地机器做fetch操作:
~~~     fetch是把远程代码作为本地的一个其他分支下载到本地,并不更新本地分支,
~~~     这里的命令是把远程的”master“分支下载到本地作为一个新的分支”test“存在

[root@server12 shell]# cat mem.sh
[root@server12 shell]# git fetch origin master:test
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From master:/git-test/shell
 * [new branch]      master     -> test
   b522245..10f9569  master     -> origin/master
### --- 查看本地文件并没有发生变化

[root@server12 shell]# cat mem.sh
[root@server12 shell]# ls 
mem.sh
[root@server12 shell]# cat mem.sh
free -m | awk 'NR==2{print $4}'
echo hello
echo ni hao
### --- 用diff查看本地master分支和fetch下来的test分支有什么区别:

[root@server12 shell]# cat mem.sh
[root@server12 shell]# cat mem.sh
[root@server12 shell]# git diff master test
diff --git a/mem.sh b/mem.sh
index 7ce0803..c0c8cef 100644
--- a/mem.sh
+++ b/mem.sh
@@ -1,3 +1,4 @@
 free -m | awk 'NR==2{print $4}'
 echo hello
 echo ni hao
+echo ha ha
### --- 如果发现fetch下来的代码没什么问题,可以选择和本地分支进行合并

[root@server12 shell]# cat mem.sh
[root@server12 shell]# git merge
Updating eb8645c..10f9569
Fast-forward
 mem.sh | 1 +
 1 file changed, 1 insertion(+)
[root@server12 shell]# cat mem.sh
free -m | awk 'NR==2{print $4}'
echo hello
echo ni hao
echo ha ha

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(13)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示