|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 -m ‘Its note:add 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
分类:
cdv015-jenkins2
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通