Git学习

Git

image-20220513101121034

rm -rf / 切勿在Linux中尝试!删除电脑中全部文件

Git 配置

查看配置 git config -l

Pandas@user MINGW64 /d/Course/01Git/gitcode
$ 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=D:/Software/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
core.usebuiltinfsmonitor=true
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master
user.name=Charles
user.email=2427592909@qq.com
credential.https://gitee.com.provider=generic

查看本地配置 git config --system --list

  • 本地配置文件地址

    D:\Software\Git\etc\gitconfig

    image-20220513103622485

Pandas@user MINGW64 /d/Course/01Git/gitcode
$ 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=D:/Software/Git/mingw64/ssl/certs/ca-bundle.crt
core.autocrlf=true
core.fscache=true
core.symlinks=false
core.usebuiltinfsmonitor=true
pull.rebase=false
credential.helper=manager-core
credential.https://dev.azure.com.usehttppath=true
init.defaultbranch=master

查看用户自己的配置 git config --global --list

Pandas@user MINGW64 /d/Course/01Git/gitcode
$ git config --global --list
user.name=Charles
user.email=2427592909@qq.com
credential.https://gitee.com.provider=generic

image-20220513102713226

  • 用户配置文件地址

    C:\Users\Pandas.gitconfig

image-20220513103700265

新电脑必配置

image-20220513104128255

image-20220513104159395

本地仓库搭建

# 在当前目录新建一个Git代码库

git init

image-20220513105511865

image-20220513105539966

克隆远程仓库

# 克隆一个项目和它的整个代码历史(版本信息)

Pandas@user MINGW64 /d/Course/01Git/gitcode01
$ git clone https://gitee.com/kuangstudy/kuang_livenote.git

image-20220513110718288

查看文件状态

Pandas@user MINGW64 /d/Course/01Git/gitcode (master)
$ git status

当初始化后,没有文件时

Snipaste_2022-05-13_11-15-29

image-20220513111900999

而当有一个hello.txt文件时

image-20220513112051395

git add . ##添加所有文件到暂存区

image-20220513112339972

git commit -m 	##提交暂存区中的内容到本地仓库 -m 提交版本信息

image-20220513114359826

忽略文件

有些时候我们不想把某些文件纳入版本控制中,比如数据库文件,临时文件,设计文件等

在主目录下建立".gitignore"文件,此文件有如下规则:

  1. 忽略文件中的空行或以井号(#)开始的行将会被忽略。
  2. 可以使用Linux通配符。例如:星号(*)代表任意多个字符,问号(?)代表一个字符,方括号([abc])代表可选字符范围,大括号({string1,string2,…})代表可选的字符串等。
  3. 如果名称的最前面有一个感叹号(!),表示例外规则,将不被忽略。
  4. 如果名称的最前面是一个路径分隔符(/),表示要忽略的文件在此目录下,而子目录中的文件不忽略。
  5. 如果名称的最后面是一个路径分隔符(/),表示要忽略的是此目录下该名称的子目录,而非文件(默认文件或目录都忽略)。
#为注释
*.txt        #忽略所有 .txt结尾的文件,这样的话上传就不会被选中!
!lib.txt     #但lib.txt除外
/temp        #仅忽略项目根目录下的TODO文件,不包括其它目录temp
build/       #忽略build/目录下的所有文件
doc/*.txt    #会忽略 doc/notes.txt 但不包括 doc/server/arch.txt

image-20220513121559261

image-20220513121729261

  • 设置本机绑定SSH公钥,实现免密码登录!
# 进入 C:\Users\Administrator\.ssh 目录
# 生成公钥
ssh-keygen

image-20220513122904668

image-20220513122935077

image-20220513123058280

ssh-keygen -t rsa	#生成公钥

image-20220513123332473

生成完之后就会生成两个文件

image-20220513123541322

image-20220513124706850

image-20220513124901511

image-20220513125019784

image-20220513125519908

image-20220513125542903

image-20220513125642945

image-20220513130223760

image-20220513130404286

流程

image-20220513132616906

  • git push 后填写用户名和密码

image-20220513132807384

image-20220513132827759

  • 远程仓库和本地仓库文件一样,提交成功

image-20220513132957063

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值