Git
Git 使用 SHA-1 算法计算数据的校验和,通过对文件的内容或目录的结构计算出一个 SHA-1 哈希值,作为指纹字符串。
Config
查看 git config
# 查看当前项目 config
git config -l
# 查看全局 config
git config --global -l
配置用户名密码
# 为当前项目配置
git config user.email "wolffn@xxx.com"
git config user.name wolfFN
# 全局配置
git config --global user.email "wolffn@xxx.com"
git config --global user.name "theox"
SSH KEY
生成 ssh key, 并上传至 Github/ 其他托管平台
生成 ssh key: (此处以 github 为例,其他平台类似)
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
# Generating public/private rsa key pair...
# 三次回车即可生成 ssh key
查看你的 public key,并把他添加到 Github
cat ~/.ssh/id_rsa.pub
# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....
校验登录:
ssh -T git@github.com
# Attempts to ssh to GitHub
# 输入 yes
# Hi [username]! You've successfully authenticated, but GitHub does not provide shell access.
Init
Local init
touch README.md
git init
git add README.md
git commit -m "first commit"
Remote repository
# 建立与远程仓库的关联
git remote add origin https://github.com/...
git push -u origin master
# update origin
git remote set-url [url]
# remove origin
git remote rm origin
Pull
# fetch 命令只是将远端的数据拉到本地仓库,并不自动合并到当前工作分支
git fetch [remote-name]
git pull [remote-name] [branch-name]
git remote show origin # 显示远程信息
git remote show [remote-name] # 查看某个远程仓库的详细信息
git remote -v # 列出remote
Log
git log --pretty=oneline
# 限制条数
git log -20 --pretty=oneline
git log --graph
# 查看某个作者的提交
git log --author="[username]"
# 查找关键词
git log -S [关键词]
# 查找特定提交, 根据 JRA(issue) 编号
git log --grep="JRA-224:"
Branch
删除分支
git branch -D [branch-name] # 删除本地分支
git push origin :[branch-name] # 删除远程分支
git remote prune origin # 删除远程分支残留 refs/remotes/origin/[branch-name]
git branch --merged # 查看已经合并的分支。
git branch -no-merged # 查看尚未合并的分支
git branch -v #查看各个分支最后一个提交对象的信息。
git branch [branch-name] # 创建一个新的分支
git checkout [branch-name] # 切换到其他分支
git checkout -b [branch-name] # 创建, 并切换到新的分支
Commit
git commit --amend # 追加commit, 也可以用来修改 commit msg
git add . # 将当前目录下的修改,添加至暂存区(staged)
git commit -a # 自动commit tracked的文件
git diff --cached/staged # 查看已暂存的文件改动
git mv [old] [new] # 移动文件
git rm [file-name] # 删除文件
git rm --cached [file-name] # 不再追踪文件