config
-
git config --global user.name "[user name]"
配置永久个人用户名 -
git config --global user.email "[email]"
配置永久个人邮箱 -
git config --global core.editor [editor name]
配置永久编辑器 -
git config --global merge.tool [Variance analysis tools]
配置解决冲突时的差异分析工具
ssh
-
cat ~/.ssh/id_rsa.pub
检查系统是否已在默认位置具有一个密钥对 -
ssh-keygen -o -t rsa -C "your.email@example.com" -b 4096
生成新的密钥对 -
cat ~/.ssh/id_rsa.pub | clip
copy生成的密钥对到剪切板上
clone
-
git clone [remoteUrl]
默认copy -
git clone -b [branchName] [remoteUrl]
copy远程仓库指定的分支,并在本地创建此分支
fetch
-
git fetch [remoteName]
抓取远程仓库有而本地没有的数据 -
git remote add
添加一个新的远程仓库引用到当前的项目
merge
-
git merge [branchName]
合并指定分支到当前分支 -
git merge [remoteName] / [branchName]
合并由于fetch远程分支所生成的指针的内容
pull
push
-
git push ([remoteName]) ([branchName])
推送本地修改值指定远程仓库的指定分支 -
git push -f
强行推送
add
commit
push
stash
储藏功能,用于当前工作未完成,却要切换分支时,保存当前工作修改
-
git stash save "message"
stash当前所有修改 -
git stash apply
还原所有,还原后stash依然存在,需要drop删除 -
git stash apply stash[NUM]
还原指定序号的stash -
git stash drop
删除所有stash -
git stash drop stash[NUM]
删除指定stash NUM为序号
branch
分支
-
git branch
查看本地分支列表 -
git branch -v
查看本地分支列表,包含最后一次提交信息 -
git branch -vv
查看本地分支列表,包含最后一次提交信息以及远程分支对应关系 -
git branch --merged
查看本地分支列表,限制为已合并到当前分支的选项 -
git branch --no-merged
查看本地分支列表,限制为未合并到当前分支的选项 -
git branch --set-upstream-to=origin/@{branchNameA] [branchNameB]
关联本地分支与远程分支 -
git branch -d [branchName]
删除分支 -
git branch -D [branchName]
强行删除分支 git branch -d -r origin/[branchName]
-
git branch [newBranchName]
新建一个分支 -
git branch -f [newBranchName]
强行新建一个分支 -
git branch [newBranchName] [commitId]
基于当前分支指定的提交新建一个分支 -
git checkout [branchName ]
切换分支 -
git checkout -b [newBranchName]
新建并切换到一个新的分支 -
git checkout -b [newBranchName] [commitId]
基于当前分支指定的提交新建并切换到一个新分支 -
git checkout -b [newBranch] [remoteName]/[branchName]
基于指定远程仓库的远程分支新建并且换到一个新的本地分支,并建立新本地分支与远程分支的联系 -
git checkout --track [remoteName] / [branchName]
基于指定远程仓库的远程分支新建并且换到一个新的本地分支,并建立新本地分支与远程分支的联系,新分支名称与远程分支相同
remote
远程引用
-
git remote add origin git@github.com:git_username/repository_name.git
在本地目录下关联远程repository -
git ls-remote ([remoteName])
显式地获得远程引用的完整列表 -
git remote show ([remoteName])
获得远程分支的更多信息 -
git remote -v
查看远程仓库地址
tag
reset
-
git reset HEAD <file>...
取消指定文件的暂存 -
git reset <param> HEAD~1
撤回上个版本commit操作,param
说明:--mixed
: 默认,不删除代码改动,撤销commit与add;--soft
不删除代码,撤销commit,不撤销add;--hard
删除代码改动,撤销commit与add -
git reset <param> HEAD~2
撤回两个commit(如果有) -
git reset -- hard <commitId>
还原到指定提交
rebase
-
git rebase [branchName]
把指定分支的提交拿到我的新提交之前,(新提交:拉取点之后的提交) -
git rebase -i HEAD~4
合并四次提交记录 参考链接
网友评论