Git
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
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
-
用户配置文件地址
C:\Users\Pandas.gitconfig
新电脑必配置
本地仓库搭建
# 在当前目录新建一个Git代码库
git init
克隆远程仓库
# 克隆一个项目和它的整个代码历史(版本信息)
Pandas@user MINGW64 /d/Course/01Git/gitcode01
$ git clone https://gitee.com/kuangstudy/kuang_livenote.git
查看文件状态
Pandas@user MINGW64 /d/Course/01Git/gitcode (master)
$ git status
当初始化后,没有文件时
而当有一个hello.txt文件时
git add . ##添加所有文件到暂存区
git commit -m ##提交暂存区中的内容到本地仓库 -m 提交版本信息
忽略文件
有些时候我们不想把某些文件纳入版本控制中,比如数据库文件,临时文件,设计文件等
在主目录下建立".gitignore"文件,此文件有如下规则:
- 忽略文件中的空行或以井号(#)开始的行将会被忽略。
- 可以使用Linux通配符。例如:星号(*)代表任意多个字符,问号(?)代表一个字符,方括号([abc])代表可选字符范围,大括号({string1,string2,…})代表可选的字符串等。
- 如果名称的最前面有一个感叹号(!),表示例外规则,将不被忽略。
- 如果名称的最前面是一个路径分隔符(/),表示要忽略的文件在此目录下,而子目录中的文件不忽略。
- 如果名称的最后面是一个路径分隔符(/),表示要忽略的是此目录下该名称的子目录,而非文件(默认文件或目录都忽略)。
#为注释
*.txt #忽略所有 .txt结尾的文件,这样的话上传就不会被选中!
!lib.txt #但lib.txt除外
/temp #仅忽略项目根目录下的TODO文件,不包括其它目录temp
build/ #忽略build/目录下的所有文件
doc/*.txt #会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
- 设置本机绑定SSH公钥,实现免密码登录!
# 进入 C:\Users\Administrator\.ssh 目录
# 生成公钥
ssh-keygen
ssh-keygen -t rsa #生成公钥
生成完之后就会生成两个文件
流程
- git push 后填写用户名和密码
- 远程仓库和本地仓库文件一样,提交成功