git笔记。

常用命令

查看用户配置信息

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目
$ git config -l
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=G:/Git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
credential.helper=manager
user.name=zhouwenfeng
user.email=1405377877@qq.com

查看系统配置

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目
$ git config --system --list
diff.astextplain.textconv=astextplain
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
http.sslbackend=openssl
http.sslcainfo=G:/Git/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
credential.helper=manager

全局配置

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目
$ git config --global --list
user.name=zhouwenfeng
user.email=1405377877@qq.com

Git相关的配置文件

  1. Git\etc\gitconfig : Git安装目录下的gitconfig --system 系统级
  2. C:\Users\zwf12.gitconfig 只适用于当前登录用户的配置 --global 全局

Git配置用户信息

git config --global user.name "zwf"
git config --global user.email "1405377877@qq.com"

Git工作原理

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-unbZvalb-1655697184933)(C:\Users\zwf12\AppData\Roaming\Typora\typora-user-images\image-20220513100638256.png)]

  • Working Directory 工作目录 (就是平时存放代码的地方)
  • index/Stage:暂存区,用于临时存放你的改动,实际就是一个文件,保存即将提交的文件列表信息
  • Repository:存库区(或者本地仓库),就是安全存放数据的位置,这里有你提交的所有版本的数据。
  • Remote:远程仓库

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-G5UvBHrr-1655697184934)(C:\Users\zwf12\AppData\Roaming\Typora\typora-user-images\image-20220513101711143.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XfKqL7QD-1655697184935)(C:\Users\zwf12\AppData\Roaming\Typora\typora-user-images\image-20220513101724726.png)]

查看本地库状态

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g
$ git init #初始化本地库
Initialized empty Git repository in F:/git远程存库项目/g/.git/

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git status #查看本地库状态
On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ vim #hello.txt #编写一个文件

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ ls #查看当前目录
hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ cat hello.txt # 查看该文件
holle git!git
git
git
git
git
git
git
git
git
git
git
git
git

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git status  #查看本地库状态
On branch master #当前所在的分支

No commits yet #当前没有需要提交的数据

Untracked files: #未被追踪的文件
  (use "git add <file>..." to include in what will be committed)
        hello.txt

nothing added to commit but untracked files present (use "git add" to track)


提交到暂存区


zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.txt


zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git rm --cached hello.txt  #删除暂存区的文件
rm 'hello.txt'

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git status
On branch master

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        hello.txt

nothing added to commit but untracked files present (use "git add" to track)

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git add hello.txt #添加到暂存区
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory


提交本地库


zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   hello.txt


zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git commit -m "first commit" hello.txt # 提交到本地库
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
[master (root-commit) 610c4e8] first commit
 1 file changed, 13 insertions(+)
 create mode 100644 hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git status
On branch master
nothing to commit, working tree clean

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git reflog #查看日志
610c4e8 (HEAD -> master) HEAD@{0}: commit (initial): first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git log  #查看详细日志
commit 610c4e86d8f038d117cc57cdab801cdc89c50dc1 (HEAD -> master)
Author: zhouwenfeng <1405377877@qq.com>
Date:   Thu May 19 16:01:45 2022 +0800

    first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$

修改文件

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ ls
hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ vim hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ 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")

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git add hello.txt #添加暂存区
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git commit -m "second commit" hello.txt #第二次提交
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory
[master a875d72] second commit
 1 file changed, 1 insertion(+), 1 deletion(-)

版本窜梭

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git reflog #查看版本日志
8ab75a2 (HEAD -> master) HEAD@{0}: commit: third commit
a875d72 HEAD@{1}: commit: second commit
610c4e8 HEAD@{2}: commit (initial): first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git reset --hard 610c4e8 #版本窜梭
HEAD is now at 610c4e8 first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git reflog 
610c4e8 (HEAD -> master) HEAD@{0}: reset: moving to 610c4e8
8ab75a2 HEAD@{1}: commit: third commit
a875d72 HEAD@{2}: commit: second commit
610c4e8 (HEAD -> master) HEAD@{3}: commit (initial): first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ cat hello.txt #查看第一次提交的版本信息
holle git!git
git
git
git
git
git
git
git
git
git
git
git
git


git分支

查看分支

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git branch -v # 查看分支
* master 610c4e8 first commit

添加分支

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git branch -v
* master 610c4e8 first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master) 
$ git branch hot-fix # 添加分支

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git branch -v
  hot-fix 610c4e8 first commit
* master  610c4e8 first commit

切换分支

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git branch -v
* master 610c4e8 first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git branch hot-fix

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git branch -v
  hot-fix 610c4e8 first commit
* master  610c4e8 first commit

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git checkout hot-fix
Switched to branch 'hot-fix'

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git branch -v
* hot-fix 610c4e8 first commit #当前分支
  master  610c4e8 first commit

修改分支


zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ ls
hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ vim hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ cat hello.txt
holle git!git hot-fis

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ 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")

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git add hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git commit -m "fix"
[hot-fix da0add4] fix
 1 file changed, 1 insertion(+), 13 deletions(-)

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git status
On branch hot-fix
nothing to commit, working tree clean

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$

合并分支


zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git checkout master #切换分支
Switched to branch 'master'

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ cat hello.txt
holle git!git
git
git
git
git
git
git
git
git
git
git
git
git

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git merge hot-fix #合并分支
Updating 610c4e8..da0add4
Fast-forward
 hello.txt | 14 +-------------
 1 file changed, 1 insertion(+), 13 deletions(-)

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ cat hello.txt
holle git!git hot-fis

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$

冲突合并

冲突产生的原因:

​ 合并分支时,两个分支在同一个文件的同一个位置有两套完全不同的修改,Git无法替我们决定使用哪一个。必须人为决定新代码内容。


zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ vim hello.txt #修改内容

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ cat hello.txt #查看内容
holle git!git hot-fis
master test

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git add hello.txt #添加暂存区

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git commit -m "matser test" hello.txt  #提交本地仓库
[master fc5aeb7] matser test
 1 file changed, 2 insertions(+), 1 deletion(-)

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ git checkout hot-fix # 切换分支
Switched to branch 'hot-fix'

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ ls #查看目录
hello.txt

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ vim hello.txt #修改文件

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git add hello.txt #添加暂存区

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git commit -m "hot-fix test" hello.txt #提交本地
[hot-fix 5ddf995] hot-fix test
 1 file changed, 3 insertions(+), 1 deletion(-)

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (hot-fix)
$ git checkout master #切换分支
Switched to branch 'master'

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (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. #报错

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master|MERGING)
$ git status #查看状态
On branch master
You have unmerged paths.
  (fix conflicts and run "git commit")
  (use "git merge --abort" to abort the merge)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
        both modified:   hello.txt

no changes added to commit (use "git add" and/or "git commit -a") 

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master|MERGING)
$ vim hello.txt #手动修改

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master|MERGING)
$ git add hello.txt #重新添加

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master|MERGING)
$ git commit -m "merge" #提交 这里不要带文件名
[master 54f8033] merge

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ cat hello.txt #查看文件
holle git!git hot-fis
master test

hot-fix test


anges added to commit (use “git add” and/or “git commit -a”)

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master|MERGING)
$ vim hello.txt #手动修改

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master|MERGING)
$ git add hello.txt #重新添加

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master|MERGING)
$ git commit -m “merge” #提交 这里不要带文件名
[master 54f8033] merge

zwf12@LAPTOP-OBHSG3VD MINGW64 /f/git远程存库项目/g (master)
$ cat hello.txt #查看文件
holle git!git hot-fis
master test

hot-fix test


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值