-
查看远程仓库地址:
git remote -v
-
添加远程仓库地址:
git remote add <仓库别名> <远程仓库地址>
-
修改远程仓库地址:
git remote set-url origin <url>
或 先删后加
git remote rm origin
git remote add origin [url]
-
合并两个不同远程仓库的Git命令
跳转 -
tag相关操作
- 查看标签:
git tag --list
- 打标签:
git tag -a v1.0 -m "xx"
- 删本地标签:
git tag -d v1.0
- 删远程标签:
git push origin :refs/tags/v1.0
- 切换标签:
git checkout [tag/branch/commit] // 切换到指定tag/branch/commit都是此命令
- 同步至远程:
git push origin --tags
- 查看标签:
-
创建分支
git checkout -b [branch]
git branch [branch]
-
分支合并到主干
git checkout master
->git merge master
-
推送主干/分支到远程
git push origin [branch]
-
删除远程分支
git push origin --delete [branch_name]
-
stash缓存相关
- 保存:
git stash save "save message"
- 查看列表:
git stash list
- 查看变动:
git stash show
默认show第一个存储,如果要显示其他存贮,后面加stash@{$num},比如第二个git stash show stash@{1}
- 删除并恢复缓存:
git stash pop
恢复第二个git stash pop stash@{1}
- 恢复但不删除缓存:
git stash apply
恢复第二个git stash apply stash@{1}
- 从列表删除:
git stash drop stash@{$num}
- 全部删除:
git stash clear
- 保存:
-
关联并同步上游仓库
跳转 -
回滚提交
$ git reset --hard HEAD^
回退到上个版本
$ git reset --hard HEAD~3
回退到前3次提交之前,以此类推,回退到n次提交之前
$ git reset --hard commit_id
退到/进到 指定commit的sha码 -
统计代码行数
git log --author="zengchenwei" --since="2020/09/01" --until="2020/09/03" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }'