系列文章:这个系列已完结,如对您有帮助,求点赞收藏评论。
读者寄语:再小的帆,也能远航!
Coding平台官方链接
拥有以下功能:
是一个比较好的管理工具,还可以以记录版本的形式写文档(非广子,coding官方看到可给我打钱)
废话不多说,主要有以下流程:(自己总结的,不喜勿喷,可选择自己喜欢的方式)
Coding创建代码仓库–>本地创建git代码仓库–>本地代码仓库克隆Coding代码仓库以进行关联–>本地代码仓库中进行开发–>本地推送到Coding仓库–>创建制品仓库–>Coding代码仓库构建计划制作镜像制品并推送到制品仓库
有三种方式:
.gitignore 文件的作用是忽略指定文件类型不进行推送,一般创建时需要添加此文件,但本次仅为测试,所以不设置这玩意儿。
我理解为本地与远程仓库关联起来了。
# 进入到一个新的目录下
17211@hqc MINGW64 /d/data/Git/git-learning
$ cd other-repo/
# 将远程仓库的文件克隆下来
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo (master)
$ git clone https://e.coding.net/hqc12/hqc/flask.git
Cloning into 'flask'...
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
Receiving objects: 100% (6/6), done.
# 进入本地拉取的这个仓库
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo (master)
$ cd flask/
直接在这个文件夹中添加文件,模拟本地开发文件
# 查看文件状态
# 可见添加了以下7个文件
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: README.md
Untracked files:
(use "git add ..." to include in what will be committed)
.gitignore
Dockerfile
Jenkinsfile
app.py
learn-git.txt
readme.txt
requirements.txt
no changes added to commit (use "git add" and/or "git commit -a")
# 跟踪所有文件,提交所有文件到暂存区
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git add .
warning: in the working copy of 'learn-git.txt', LF will be replaced by CRLF the next time Git touches it
warning: in the working copy of 'readme.txt', LF will be replaced by CRLF the next time Git touches it
# 提交文件
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git commit -m "add all the example flask files into my new_create repository"
[master 03dbc22] add all the example flask files into my new_create repository
8 files changed, 200 insertions(+), 1 deletion(-)
create mode 100644 .gitignore
create mode 100644 Dockerfile
create mode 100644 Jenkinsfile
create mode 100644 app.py
create mode 100644 learn-git.txt
create mode 100644 readme.txt
create mode 100644 requirements.txt
# 推送到远程仓库
17211@hqc MINGW64 /d/data/Git/git-learning/other-repo/flask (master)
$ git push
Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 16 threads
Compressing objects: 100% (7/7), done.
Writing objects: 100% (10/10), 2.61 KiB | 1.30 MiB/s, done.
Total 10 (delta 0), reused 0 (delta 0), pack-reused 0
To https://e.coding.net/hqc12/hqc/flask.git
43aef0c..03dbc22 master -> master
成功推送!
已完成
在此操作中将会演示如何从远端仓库拉取代码 / 上传本地代码至远端仓库,助力你的代码上云之旅
在文件夹中新建 readme.txt
和learn-git.txt
文件,在其中一个文件中写入 I'm learning git
.
创建或修改文件后调用 git add
命令,将变更的文件添加至本地 Git 仓库的暂存区(Index Stage)。
追踪特定文件时的命令:
git add readme.txt
添加多个文件的命令:
git add readme.txt learn_git.txt
如果你想一次性跟踪所有文件,则可以直接在终端输入git add
.
将拟提交的文件纳入暂存区后,运行 git commit
命令即可将文件正式提交至本地仓库,此命令将会一次性会提交暂存区中的所有文件:
git commit -m "wrote a readme and a learn_git file"
-m
后引号中的内容是你的提交说明,下面几行是终端的返回结果。养成每次提交文件时附上变更说明的习惯,以便清楚地把控提交了什么样的修改。
不确定 Git 是否精准的追踪了修改过的文件?想再次确认文件处于哪种状态?使用 git status 命令查看文件状态。
# 当前仓库里任何文件都没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
# 修改一下文件
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ vim readme.txt
# 当文件有变更,但没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
# git add即可进行跟踪
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git add readme.txt
warning: in the working copy of 'readme.txt', LF will be replaced by CRLF the next time Git touches it
# 提交到仓库
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git commit -m "wrote something in readme.txt"
[master cc16839] wrote something in readme.txt
1 file changed, 1 insertion(+)
# 当文件已跟踪且已经提交到仓库时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
只需要在本地运行 git pull
命令即可使本地与远端保持代码同步
可以在远程仓库中直接进行修改,增加文件、文件夹等操作,都会被版本记录下来。
同步功能仅对开源仓库开放。这意味着与源仓库保持一致,将覆盖导入 CODING 仓库后做出的变更。你可以在仓库设置中修改同步频率或关闭自动同步功能。
「关联仓库」功能本质上是将访问外部仓库的凭据“暂存”至 CODING,当你使用持续集成 / 部署时,能够直接调用第三方仓库作为代码源,而省去了频繁迁移的繁琐流程。
安装好Git,类似以下操作就行,记得初始化本地git代码仓库
17211@hqc MINGW64 /d/data/Git
$ mkdir git-learning # 创建git学习文件夹
17211@hqc MINGW64 /d/data/Git
$ cd git-learning/ # 进入该文件夹
17211@hqc MINGW64 /d/data/Git/git-learning
$ mkdir git-repository # 创建一个新文件夹作为仓库
17211@hqc MINGW64 /d/data/Git/git-learning
$ cd git-repository/
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository
$ git init # 初始化
Initialized empty Git repository in D:/data/Git/git-learning/git-repository/.git/
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ ls
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ ls -ah # .git文件时隐藏的,得使用这个命令才能看到
./ ../ .git/
其实这时已经将本地git仓库和coding仓库关联起来了,可以进行以后的开发推送工作了。
可以新建任何文件进行开发工作,打标签,提交,推送等
创建或修改文件后调用 git add
命令,将变更的文件添加至本地 Git 仓库的暂存区(Index Stage)。
追踪特定文件时的命令:
git add readme.txt
添加多个文件的命令:
git add readme.txt learn_git.txt
如果你想一次性跟踪所有文件,则可以直接在终端输入git add
.
将拟提交的文件纳入暂存区后,运行 git commit
命令即可将文件正式提交至本地仓库,此命令将会一次性会提交暂存区中的所有文件:
git commit -m "wrote a readme and a learn_git file"
-m
后引号中的内容是你的提交说明,下面几行是终端的返回结果。养成每次提交文件时附上变更说明的习惯,以便清楚地把控提交了什么样的修改。
不确定 Git 是否精准的追踪了修改过的文件?想再次确认文件处于哪种状态?使用 git status 命令查看文件状态。
# 当前仓库里任何文件都没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
# 修改一下文件
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ vim readme.txt
# 当文件有变更,但没有被跟踪时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git restore ..." to discard changes in working directory)
modified: readme.txt
no changes added to commit (use "git add" and/or "git commit -a")
# git add即可进行跟踪
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git add readme.txt
warning: in the working copy of 'readme.txt', LF will be replaced by CRLF the next time Git touches it
# 提交到仓库
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git commit -m "wrote something in readme.txt"
[master cc16839] wrote something in readme.txt
1 file changed, 1 insertion(+)
# 当文件已跟踪且已经提交到仓库时
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository/flask (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
只需要在本地运行 git pull
命令即可使本地与远端保持代码同步
可以在远程仓库中直接进行修改,增加文件、文件夹等操作,都会被版本记录下来。
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git branch
dev
* master
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag v1.0 # 默认给当前分支的最新提交打标签
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git log --pretty=oneline --abbrev-commit # 查看日志,果然打上了标签
0ffd5e4 (HEAD -> master, tag: v1.0, origin/master) fix the conflict2
af66d7e (dev) work done
da2a463 merged fix bug 01
493cddf fix bug 01
59d2eb3 merge with no-ff
f4adb8a add message
33d8453 confilct fixed: and simple
f4d2054 & simple
7bcec3b AND simple
7fe8404 Creating a new branch is quick.
e83baf7 add distributed
9b5d254 write a readme file
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag v0.9 af66d7e # 之前版本的修改忘记打标签了,可以根据ID号再次打上
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag -a v0.8 -m 'version 0.8 released' da2a463 # 还可以加入一些信息
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag # 查看现有的标签
v0.8
v0.9
v1.0
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git show v0.9 # 查看指定标签的信息
commit af66d7ebfe2e8fad2a4352e1feed90c51daf38b6 (tag: v0.9, dev)
Author: hqc <21120205@bjtu.edu.cn>
Date: Mon Sep 26 11:55:12 2022 +0800
work done
diff --git a/readme.txt b/readme.txt
index 881f8bd..82e9ee0 100644
--- a/readme.txt
+++ b/readme.txt
@@ -2,3 +2,4 @@ Git is a distributed version control system
Creating a new branch is quick and simple.
Add message 'No Fast Forward'.
+The work haven't been done.
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git log --pretty=oneline --abbrev-commit
0ffd5e4 (HEAD -> master, tag: v1.0, origin/master) fix the conflict2
af66d7e (tag: v0.9, dev) work done
da2a463 (tag: v0.8) merged fix bug 01
493cddf fix bug 01
59d2eb3 merge with no-ff
f4adb8a add message
33d8453 confilct fixed: and simple
f4d2054 & simple
7bcec3b AND simple
7fe8404 Creating a new branch is quick.
e83baf7 add distributed
9b5d254 write a readme file
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag -d v0.8 # 删除本地打错的标签
Deleted tag 'v0.8' (was db889a4)
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git push origin v1.0 # 将某个标签推送到远程
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:lesserror/git-repository-lab.git
* [new tag] v1.0 -> v1.0
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git push origin --tags # 一次性推送所有还没推送到远程的本地标签
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:lesserror/git-repository-lab.git
* [new tag] v0.9 -> v0.9
# 远程标签删除需要以下两步
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git tag -d v0.9 # 1 删除本地标签
Deleted tag 'v0.9' (was af66d7e)
17211@hqc MINGW64 /d/data/Git/git-learning/git-repository (master)
$ git push origin :refs/tags/v0.9 # 2 从远程删除
To github.com:lesserror/git-repository-lab.git
- [deleted] v0.9
其实就相当于一个镜像仓库,建完之后里面是空的
有一个操作指引
将准备好的代码仓库构建到制品仓库
模板中还有 推送并部署到kubernetes 这个模板,以后试试
一些环境变量之类的配置,还不大懂,直接保存
这个版本可以自己修改,比如改成 v0.0.1
制品已经推送到了制品仓库