# ssh -T git@192.168.200.200 The authenticity of host '192.168.200.200 (192.168.200.200)' can't be established. ECDSA key fingerprint is SHA256:4Ze/q+QQ5942NjyhwQiGLZCceB9mcbC759CiyjWzHYU. ECDSA key fingerprint is MD5:61:8b:1a:f7:db:19:a8:17:bb:70:e8:f7:62:f3:a1:2d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.200.200' (ECDSA) to the list of known hosts. Welcome to GitLab, @zs!
[root@k8-controller demo]# git commit -m 'add reademe' # On branch master # # Initial commit # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # readme nothing added to commit but untracked files present (use "git add" to track)
5,添加到暂存区查看状态
1 2 3 4 5 6 7 8 9 10 11 12
[root@k8-controller demo]# git add readme [root@k8-controller demo]# git status # On branch master # # Initial commit # # Changes to be committed: # (use "git rm --cached <file>..." to unstage) # # new file: readme #
[root@work-node1 git-test]# git add a b [root@work-node1 git-test]# git status # On branch main # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # new file: a # new file: b #
[root@work-node1 git-test]# git pull origin main remote: Enumerating objects: 4, done. remote: Counting objects: 100% (4/4), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From 192.168.200.200:gitlab-instance-faefd22f/git-test * branch main -> FETCH_HEAD Updating 9f2a4f7..1d14d36 Fast-forward test | 1 + 1 file changed, 1 insertion(+) create mode 100644 test [root@work-node1 git-test]# ll total 20 -rw-r--r--. 1 root root 12 Jun 29 09:33 a -rw-r--r--. 1 root root 13 Jun 29 09:33 b -rw-r--r--. 1 root root 6251 Jun 29 06:48 README.md -rw-r--r--. 1 root root 14 Jun 29 09:59 test
提交修改
完成操作后就可以进行提交修改了到仓库了,这样仓库就可以进行永久变更了
提交命令
可以通过如下的命令进行提交变更
1
git commit -m "注释"
具体注释的格式每一个公司都是不一样的,可以按照公司规范来做
提交修改
1 2 3 4 5 6
[root@work-node1 git-test]# git commit -m 'add a and b' [main 300089b] add a and b 2 files changed, 2 insertions(+) create mode 100644 a create mode 100644 b
[root@k8-controller git-test]# git push origin main Counting objects: 5, done. Delta compression using up to 6 threads. Compressing objects: 100% (2/2), done. Writing objects: 100% (4/4), 340 bytes | 0 bytes/s, done. Total 4 (delta 0), reused 0 (delta 0) remote: GitLab: You are not allowed to push code to protected branches on this project.To git@192.168.200.200:gitlab-instance-faefd22f/git-test.git ! [remote rejected] main -> main (pre-receive hook declined) error: failed to push some refs to 'git@192.168.200.200:gitlab-instance-faefd22f/git-test.git'
[root@k8-controller git-test]# git checkout master Switched to branch 'master' [root@k8-controller git-test]# git branch main * master
切换分支后我们发现活动分支已经变成了master
2,我们在当前分支做一些变更,当我们还原回到原来的分支后就会被还原回去
1 2 3 4 5 6 7 8 9 10 11 12 13 14
[root@k8-controller git-test]# echo 'hello master' > master [root@k8-controller git-test]# git add . [root@k8-controller git-test]# git commit -m 'add master' [master acd81b3] add master 1 file changed, 1 insertion(+) create mode 100644 master [root@k8-controller git-test]# ll total 24 -rw-r--r--. 1 root root 12 Jun 29 10:24 a -rw-r--r--. 1 root root 13 Jun 29 10:24 b -rw-r--r--. 1 root root 13 Jun 29 11:18 master -rw-r--r--. 1 root root 6251 Jun 29 10:23 README.md -rw-r--r--. 1 root root 18 Jun 29 10:23 test
3,我们切换回到main分支查看下效果
1 2 3 4 5 6 7 8 9
[root@k8-controller git-test]# git checkout main Switched to branch 'main' [root@k8-controller git-test]# ll total 20 -rw-r--r--. 1 root root 12 Jun 29 10:24 a -rw-r--r--. 1 root root 13 Jun 29 10:24 b -rw-r--r--. 1 root root 6251 Jun 29 10:23 README.md -rw-r--r--. 1 root root 18 Jun 29 10:23 test
[root@k8-controller git-test]# git checkout main [root@k8-controller git-test]# git branch -d master error: The branch 'master' is not fully merged. If you are sure you want to delete it, run 'git branch -D master'. [root@k8-controller git-test]# git branch -D master Deleted branch master (was acd81b3). [root@k8-controller git-test]# git branch * main
[root@k8-controller git-test]# git status # On branch master # You have unmerged paths. # (fix conflicts and run "git commit") # # Unmerged paths: # (use "git add <file>..." to mark resolution) # # both modified: master # no changes added to commit (use "git add" and/or "git commit -a") [root@k8-controller git-test]# git add . [root@k8-controller git-test]# git status # On branch master # All conflicts fixed but you are still merging. # (use "git commit" to conclude merge) # # Changes to be committed: # # modified: master # [root@k8-controller git-test]# git commit -m 'fixed conflic' [master e57d4d2] fixed conflic [root@k8-controller git-test]# git status # On branch master nothing to commit, working directory clean [root@k8-controller git-test]# git log -3 commit e57d4d2c531a2d0a7a03cd0c65a2dbcf976fcfeb Merge: 64ae4e0 366e30f Author: ls <ls@itcast.cn> Date: Wed Jun 29 23:22:47 2022 -0400
fixed conflic
commit 64ae4e02d8f82e354cb9e72023c1e5c38d5a1eaf Author: ls <ls@itcast.cn> Date: Wed Jun 29 23:14:50 2022 -0400
modify master branch , add to master
commit 366e30f54e825845235f8b33d8017097c7652fe3 Author: ls <ls@itcast.cn> Date: Wed Jun 29 23:12:14 2022 -0400
[root@k8-controller git-test]# git branch fixbug main * master [root@k8-controller git-test]# git rebase fixbug First, rewinding head to replay your work on top of it... Applying: on master branch ,add master king Using index info to reconstruct a base tree... M master Falling back to patching base and 3-way merge... Auto-merging master CONFLICT (content): Merge conflict in master Failed to merge in the changes. Patch failed at 0001 on master branch ,add master king The copy of the patch that failed is found in: /root/git/git-test/.git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue". If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".
[root@k8-controller git-test]# ll total 28 -rw-r--r--. 1 root root 12 Jun 30 00:53 a -rw-r--r--. 1 root root 13 Jun 30 00:53 b -rw-r--r--. 1 root root 8 Jun 30 00:58 feature -rw-r--r--. 1 root root 137 Jun 30 01:12 master -rw-r--r--. 1 root root 0 Jun 30 00:52 readme -rw-r--r--. 1 root root 6251 Jun 30 00:52 README.md -rw-r--r--. 1 root root 18 Jun 30 00:52 test [root@k8-controller git-test]# cat master master master-append feature-append <<<<<<< HEAD fixbug branch ,fix1604bug ======= master king >>>>>>> on master branch ,add master king [root@k8-controller git-test]# vi master [root@k8-controller git-test]# git add . [root@k8-controller git-test]# git rebase --continue master: needs merge You must edit all merge conflicts and then mark them as resolved using git add
查看日志
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@k8-controller git-test]# git log --graph --decorate --all * commit 2fbcfedb4bb7237eb71ebd07031832fb8ba0cc03 (HEAD, master) | Author: ls <ls@itcast.cn> | Date: Thu Jun 30 01:11:07 2022 -0400 | | on master branch ,add master king | * commit 3d6704cf59d410963cad2ff6746dc2b50eb9ddf2 (fixbug) | Author: ls <ls@itcast.cn> | Date: Thu Jun 30 01:09:02 2022 -0400 | | on fixbug branch ,fixed master |