Git使用
使用Git管理代码
-
在github中创建仓库  -
在项目中添加git管理  -
进行git操作 HEAD : 当前版本  git命令大全
$ git init
$ git add .
$ git commit -m "xxx"
$ git remote add origin https://xxx
$ git push -u origin master
$ git push [origin] --tags
$ git push origin [tagname]
$ git push -f origin master
$ git pull origin master
$ git remote add origin https://xxx
$ git remote -v
$ git remote rm origin
$ ssh -T git@github.com
$ git fetch origin '远程分支名'
$ git branch (-c|-C) '分支名称'
$ git branch (-M|-m) '分支名称'
$ git branch (-v|-vv)
$ git switch -c '分支名'
$ git switch '分支名'
$ git merge '分支名'
$ git branch -d '分支名'
$ git checkout -b "本地分支名" "远程分支名"
$ git tag "标签名"
$ git tag "标签名" -m "备注"
$ git tag -l "0*"
$ git tag -d "标签名"
$ git checkout "标签名"
$ git push --tags
$ git show v1.0.0
$ git reset "版本号"
$ git reset --hard HEAD^
$ git checkout -- file
$ git reset HEAD .
$ git log
$ git reflog
$ git status
$ git diff
$ git clean -df
git全局设置
git config --global user.name "Andermi"
git config --global user.email "xing_yi_bin@163.com"
本地生成秘钥
本地Git仓库和GitHub仓库之间的传输是通过SSH加密,需要设置:
-
创建SSH Key 如果一切顺利的话,可以在用户主目录里找到.ssh 目录,里面有id_rsa 和id_rsa.pub 两个文件,这两个就是SSH Key的秘钥对,id_rsa 是私钥,不能泄露出去,id_rsa.pub 是公钥,可以放心地告诉任何人。
ssh-keygen -t rsa -C "youremail@example.com"
-
第2步:登陆GitHub -> setting 然后,点“Add SSH Key”,填上任意Title,在Key文本框里粘贴id_rsa.pub 文件的内容:  -
为什么GitHub需要SSH Key呢?因为GitHub需要识别出你推送的提交确实是你推送的,而不是别人冒充的,而Git支持SSH协议,所以,GitHub只要知道了你的公钥,就可以确认只有你自己才能推送
在 HTTPS 端口使用 SSH
如果使用ssh来push的时候出现这种错误:不能使用22端口进行连接:

解决方案:
-
在用户主目录,也就时我们生成公钥秘钥的那个文件里,touch config 生成config -
请在 ~/.ssh/config 编辑该文件,并添加以下部分: Host github.com
Hostname ssh.github.com
Port 443
User git

可以push了

添加 .gitignore 文件
touch .gitignore
以【/】表示目录以【*】匹配多个字符以【?】匹配单个字符
以【[]】匹配字符列
以【!】忽略文件或者目录
*.class
aaa/*
|