- 新建分支
git checkout -b 分支 // 新建本地分支
- 删除分支
git branch -D 分支 // 删除本地分支
- 远端分支相关
// 新建远端分支
git push --set-upstream origin 分支名
// 将本地分支推到远端
git push origin 本地分支名:远端分支名
// 将远端分支拉到本地
git fetch
git checkout -b 本地分支名 origin/远程分支名
// 删除远端分支
git push origin :远端分支名 // 推动空分支 相当于删除
git push origin --delete 远端分支名
// 查看是否关联远程仓库
git remote -v
//取消关联远程仓库
git remote remove origin
- 回滚,代码覆盖相关
// 强制使用远端代码覆盖本地
git fetch --all
git reset --hard origin/分支名
git pull
// 回到某次提交
git log
git reset --hard commitID
- stash相关
git stash save "" // 存储
git stash list // 查看stash列表
git stash show // 默认显示第一个存储改动,如果要显示的,后面加stash@{$num}
git stash apply // 将存储释放,但不会从存储列表中删除,git stash apply stash@{1}
git stash pop // 恢复之前缓存的工作目录,将缓存对应stash删除,git stash pop stash@{1}
git stash drop stash@{$num} // 从列表删除
git stash clear // 清空缓存列表
- 删除远端文件夹但不删除本地
//删除远端文件夹,但不删除本地(比如:误将node_modules传到远端的情况)
git rm -r --cached 文件夹名 // --cached不会把本地的.idea删除
git commit -m '' // 提交代码
git push -u origin 分支名 // 将代码推到远端
- 源
git remote set-url origin 源地址 // 修改源
- tag相关
git tag v1.0 // 新建tag
git tag -a tagName -m "项目号" // 提交tag
git push origin v1.0 // 推送单个tag
git push origin --tags // 推送所以tag
git checkout tag名字 // 切换tag
git tag -d v1.0 // 删除
git push origin :refs/tags/v1.0 // 删除远端tag
git show tag名字 // 查看tag的详细信息
git tag // 所有的tag
欢迎指正补充