赞
踩
Git是一个免费的、开源的分布式版本控制系统。公司里面是关联代码的工具。
版本控制是一种记录文件内容变化,以便将来查阅特定版本修订情况的系统。
代码托管中心是基于网络服务器的远程代码仓库,一般我们简单称为远程库。
CZyue@LAPTOP-K3L5FM3D MINGW64 ~/Desktop
$ git --version
git version 2.37.2.windows.2
CZyue@LAPTOP-K3L5FM3D MINGW64 ~/Desktop
$ git config --global user.name fenfen
CZyue@LAPTOP-K3L5FM3D MINGW64 ~/Desktop
$ git config --global user.email yqlmjhckn@163.com
CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo
$ git init
Initialized empty Git repository in D:/学习/专业学习/3-基本技能类/Git/git demo/.git/
CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo (master) $ ll -a total 4 drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 ./ drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:50 ../ drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 .git/ CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo (master) $ cd .git/ CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo/.git (GIT_DIR!) $ ll -a total 11 drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 ./ drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 ../ -rw-r--r-- 1 CZyue 197121 23 Aug 30 19:53 HEAD -rw-r--r-- 1 CZyue 197121 130 Aug 30 19:53 config -rw-r--r-- 1 CZyue 197121 73 Aug 30 19:53 description drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 hooks/ drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 info/ drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 objects/ drwxr-xr-x 1 CZyue 197121 0 Aug 30 19:53 refs/
# 创建一个文件 $ vim hello.txt $ ll total 1 -rw-r--r-- 1 CZyue 197121 198 Aug 30 20:06 hello.txt $ cat hello.txt hello Git! hello Git! hello Git! hello Git! hello Git! # 再次看下git本地库状态,有可以提交的了 $ git status On branch master No commits yet Untracked files: # git还未追踪过的文件 (use "git add <file>..." to include in what will be committed) hello.txt
$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
# 警告是在说我帮你自动转换换行符啦
$ git status
On branch master
No commits yet
Changes to be committed: # 只是提交到了暂存区
(use "git rm --cached <file>..." to unstage)
new file: hello.txt
$ git rm --cached hello.txt # 只是删了暂存区,工作区还是有的
rm 'hello.txt'
$ git commit -m "first commit" hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
[master (root-commit) 21fb5ab] first commit # 主干master分支第一次提交
1 file changed, 18 insertions(+) # 一个文件被改变,16行文件被插入
create mode 100644 hello.txt
$ git status
On branch master
nothing to commit, working tree clean
$ git reflog
21fb5ab (HEAD -> master) HEAD@{0}: commit (initial): first commit # 有一个版本first commit
或者
$ git log
commit 21fb5ab3759730b817bbe240eccf17d18114b6e4 (HEAD -> master)
Author: fenfen <yqlmjhckn@163.com>
Date: Tue Aug 30 19:58:37 2022 +0800
first commit
$ vim hello.txt
hello world!!!
hello Git!
hello Git!
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: hello.txt # 被修改过的文件
no changes added to commit (use "git add" and/or "git commit -a")
$ git add hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: hello.txt
$ git commit -m "second commit" hello.txt
warning: in the working copy of 'hello.txt', LF will be replaced by CRLF the next time Git touches it
[master 6e1f647] second commit
1 file changed, 1 insertion(+) # git按照行维护文件的
$ git status
On branch master
nothing to commit, working tree clean
$ git reflog
6e1f647 (HEAD -> master) HEAD@{0}: commit: second commit
21fb5ab HEAD@{1}: commit (initial): first commit
或者
$ git log
commit 6e1f647416a9fe798465821faebfe2366897586f (HEAD -> master)
Author: fenfen <yqlmjhckn@163.com>
Date: Tue Aug 30 20:37:35 2022 +0800
second commit
commit 21fb5ab3759730b817bbe240eccf17d18114b6e4
Author: fenfen <yqlmjhckn@163.com>
Date: Tue Aug 30 20:58:37 2022 +0800
first commit
$ cat hello.txt
hello world!!!
hello Git!
hello Git!
$ cat hello.txt
hello world!!!
hello dear!!
hello Git!
hello Git!
从始至终,显示的也是只有一个文件,因为不是靠副本控制的,底层靠的是head指针控制的
$ git reflog
$ git log
$ git reset --hard 6e1f647
HEAD is now at 6e1f647 second commit
$ git reflog
6e1f647 (HEAD -> master) HEAD@{0}: reset: moving to 6e1f647 # 日志记下来版本穿梭
148629d HEAD@{1}: commit: third commit
6e1f647 (HEAD -> master) HEAD@{2}: commit: second commit # 指针就跑到这边来了
21fb5ab HEAD@{3}: commit (initial): first commit
$ cat hello.txt
hello world!!!
hello Git
$ git branch -v
* master 6e1f647 second commit # 确实只有一个分支
git branch 分支名
$ git branch hot-fix
# 再次查看分支,有两
$ git branch -v
hot-fix 6e1f647 second commit
* master 6e1f647 second commit
git checkout 分支名
CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo (master) #最后master说明是在master上面的
$ git checkout hot-fix # 切换下分支
Switched to branch 'hot-fix'
CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo (hot-fix) #切换好了,就在hot—fix上面了
# 再查看下分支,*在hot-fix上了
$ git branch -v
* hot-fix 6e1f647 second commit
master 6e1f647 second commit
# 修改代码 $ vim hello.txt hello world!!! 22222 hello Git 33333 # 看下本地库状态 $ git status On branch hot-fix Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: hello.txt no changes added to commit (use "git add" and/or "git commit -a") # 提交到暂存区 $ git add hello.txt $ git status On branch hot-fix Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: hello.txt # 提交本地库 $ git commit -m "hot-fix first commit" hello.txt [hot-fix 77561c6] hot-fix first commit 1 file changed, 2 insertions(+), 2 deletions(-) # 看下最新代码 $ cat hello.txt hello world!!! 22222 hello Git! 33333 # 看下版本情况 $ git reflog 77561c6 (HEAD -> hot-fix) HEAD@{0}: commit: hot-fix first commit 6e1f647 (master) HEAD@{1}: checkout: moving from master to hot-fix 6e1f647 (master) HEAD@{2}: reset: moving to 6e1f647 148629d HEAD@{3}: commit: third commit 6e1f647 (master) HEAD@{4}: commit: second commit 21fb5ab HEAD@{5}: commit (initial): first commit
git merge 分支名
# 必须站在master上合并才可以 CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo (hot-fix) $ git checkout master Switched to branch 'master' # 看眼代码 CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo (master) # 代码恢复到原来的样子了 $ cat hello.txt hello world!!! hello Git! # 合并了! $ git merge hot-fix Updating 6e1f647..77561c6 Fast-forward hello.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) # 这时再去看代码,OHHHHH $ cat hello.txt hello world!!! 22222 hello Git! 33333
# master修改代码并提交
$ vim hello.txt
hello world!!! 22222 master test
hello Git! 33333
$ git add hello.txt
$ git commit -m "master test" hello.txt
[master 883cb97] master test
1 file changed, 1 insertion(+), 1 deletion(-)
$ cat hello.txt
hello world!!! 22222 master test
hello Git! 33333
# 切换到hot-fix分支
$ git checkout hot-fix
Switched to branch 'hot-fix'
$ vim hello.txt
hello world!!! 22222
hello Git! 33333 hot-fix test
$ git add hello.txt
$ git commit -m "hot-fix test" hello.txt
[hot-fix 85399a7] hot-fix test
1 file changed, 1 insertion(+), 1 deletion(-)
# 切换分支到master进行和合并
$ git checkout master
Switched to branch 'master'
$ git merge hot-fix
Auto-merging hello.txt
CONFLICT (content): Merge conflict in hello.txt
Automatic merge failed; fix conflicts and then commit the result. # 失败了,发生了合并代码冲突
# 打开文件看看先 $ cat hello.txt <<<<<<< HEAD # 当前分支代码 hello world!!! 22222 master test hello Git! 33333 ======= hello world!!! 22222 # 别的分支 hello Git! 33333 hot-fix test >>>>>>> hot-fix # 手动改吧 $ vim hello.txt hello world!!! 22222 master test hello Git! 33333 hot-fix test # 保存后还得提交一次 $ git add hello.txt $ git commit -m "merge tese" hello.txt #但是不能这么提交,文件名不要 fatal: cannot do a partial commit during a merge. CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学/专业学习/3-基本技能类/Git/git demo (master|MERGING) $ git commit -m "merge tese" [master 8159946] merge tese CZyue@LAPTOP-K3L5FM3D MINGW64 /d/学习/专业学习/3-基本技能类/Git/git demo (master) #合并完是没有merging的后缀的 $ cat hello.txt hello world!!! 22222 master test hello Git! 33333 hot-fix test # 切回hot-fix还是没修改,只有master会修改,不信切回去看 $ git checkout hot-fix Switched to branch 'hot-fix' $ cat hello.txt #真没变 hello world!!! 22222 hello Git! 33333 hot-fix test
上官网创建
给链接起个别名,
$ git remote add git-demo https://github.com/fenfenya/git-demo.git
$ git remote -v
git-demo https://github.com/fenfenya/git-demo.git (fetch)
git-demo https://github.com/fenfenya/git-demo.git (push)
# 老是推不上去,先执行
git config --global http.sslVerify false
# 还不行把windows映射把GitHub的ip和网址写进去
# 推下代码
$ git push git-demo master
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
remote: Resolving deltas: 100% (6/6), done.
$ git pull git-demo master
hello.txt | 17 -----------------
1 file changed, 17 deletions(-)
# 拉取好的代码会自动帮你提交本地库
$ git status
On branch master
nothing to commit, working tree clean
# 查看代码
$ cat hello.txt
hello world!!! 22222 master test
hello Git! 33333 hot-fix test
# 克隆
$ git clone https://github.com/Janusec/Application-Gateway.git
# 查看克隆后的消息
$ ll
total 5
drwxr-xr-x 1 CZyue 197121 0 Aug 31 20:25 Application-Gateway/
-rw-r--r-- 1 CZyue 197121 72 Aug 30 22:01 hello.txt
# 进去看看
$ cd Application-Gateway/
#连别名都有了 以orgion开头
$ git remote -v
origin https://github.com/Janusec/Application-Gateway.git (fetch)
origin https://github.com/Janusec/Application-Gateway.git (push)
$ git push https://github.com/Janusec/Application-Gateway.git master
邀请函链接一般通过沟通工具给到你,复制链接同意即可
# rsa是非对称加密协议
$ ssh-keygen -t rsa -C yqlmjhckn@163.com
# $ ll
total 5
-rw-r--r-- 1 CZyue 197121 2602 Sep 1 21:24 id_rsa
-rw-r--r-- 1 CZyue 197121 571 Sep 1 21:24 id_rsa.pub
# 找到公钥
$ cat id_rsa.pub
ssh-rsa xxxxxxxxxxxxxxxxxxxx
#用ssh链接拉取代码
$ git pull git@github.com:fenfenya/git-demo.git master
Updating fb8cafd..b9b9d6b
Fast-forward
hello.txt | 1 +
1 file changed, 1 insertion(+)
# 看下代码变化率了
$ cat hello.txt
hello world!!! 22222 master test
hello Git! 33333 hot-fix test
hello dear! 44444 ssh test
# 修改代码 $ vim hello.txt hello world!!! 22222 master test hello Git! 33333 hot-fix test hello dear! 44444 ssh pull test hello sun! 55555 ssh push test # 提交暂存区和远程库 $ git add hello.txt $ git commit -m "ssh push test commit" hello.txt [master 4d31da4] ssh push test commit 1 file changed, 2 insertions(+), 1 deletion(-) # push 代码 $ git push git@github.com:fenfenya/git-demo.git master Enumerating objects: 5, done. Counting objects: 100% (5/5), done.
# Compiled class file *.class # Log file *.log # BlueJ files *.ctxt # Mobile Tools for Java (J2ME) .mtj.tmp/ # Package Files # *.jar *.war *.nar *.ear *.zip *.tar.gz *.rar # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* .classpath .project .settings target .idea *.iml
[user]
name = fenfen
email = yqlmjhckn@163.com
[http]
sslVerify = false
[core]
excludesfile = C:/Users/asus/git.ignore
右击项目提交即可
查看版本信息
右击切换
那个黄色的就是指针了
复制ssh链接
选择自定义远程连接
略
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。