【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>>
- 初始化git仓库,生成工作区和版本库
git init
- 设置用户名与邮箱地址
git config --global user.name 'yourName'
git config --global user.email 'yourEmail'
- 查看配置信息/具体配置信息(用户名为例)
git config --list
git config user.name
- 设置默认代码推送分支
git config --global push.default branchName
git config --global push.default master
- 将文件提交到暂存区,存储在对象库中
git add fileName
- 将内容提交到指定分支
git commit -m 'comment'
- 查看提交记录/日志
git log
git log --oneline
git log dirName/fileName
- 文件重命名
git mv oldFileName newFileName
暂存区文件的修改
- 文件删除
git rm -f filename 文件强制删除
git rm --cached filename保留本地文件
- 操作撤销
git revert HEAD 当前版本,从0开始计算
git revert HEAD~2 当前的第三次
- 新建分支
git branch branchName
- 切换分支
git checkout branchName
- 分支合并
git merge branchName
git merge branchName --no--ff
- 本地分支删除
git branch -d branchName
- 删除远端分支
git branch -d branchName
git push --delete origin branchName
- 分支改动
git diff
git diff branchName1..branchName2
- 分支重命名
git branch -m oldBranchName newBrachName
- 创建并切换分支
git checkout -b branchName
- 分支封存
git stash
- 分支封存还原
git stash pop
- 讲本地仓库代码提交到github
<!--切换到需要提交的分支-->
git remote add origin https://github.com/username/test.git
<!--推送提交的内容-->
git push -u origin master
- 本地分支与远程的对应关系 `
git branch -r
- 创建分支并关联远端分支
git checkout -b branchName origin/branchName
- 移除远程关联
git remote remove origin
//恢复使用
git remote add origin https://github.com/username/test.git
//查看关联情况
git remote -v
- git命令的别名使用
git config --global alias.ci commit
- 证书秘钥生成
位于~/.ssh中id_rsa和id_rsa.pub
ssh-keygen -t rsa
将id_rsa.pub中内容复制到服务器/home/git.ssh/authorized中
- 忽略文件操作
在项目目录下新建.gitignore
然后中.gitignore中天剑需要忽略的文件
来源:oschina
链接:https://my.oschina.net/u/1397994/blog/760747