杂七杂八git

Git基本使用命令

2022-04-19  本文已影响0人  程序记录日志

Git配置

Git最小配置

git config --global user.name '账户名称'
git config --global user.email 'Email地址'
git config --local user.name '账户名称'
git config --local user.email 'Email地址'

查看相关配置

git config --global --list
git config --local --list

本地基本操作

基本操作

git status
git branch -v
git checkout 指定分支名称
git add .
git add -A
git add 文件1 文件2 ...
git commit

比较差异

git diff 某文件
git diff --cache 某文件
git diff
git diff --cache

暂存区与工作区之间回滚

git checkout 文件1 文件2 ...
git reset 文件1 文件2 ...
git reset --hard
git difftool commit1 commit2

其他

git ls-files --others

临时任务处理

git stash
git stash pop           # 把之前任务弹出
或者
git stash apply         # 从栈顶把任务取出
git stash list
git stash pop stash @{数字}

修改分支历史

git add
git commit --amend
git rebase -i (commit的id)
git add
git rebase --contiue

查看变更日志

git log --online
git log -n
git log --online --graph --all
git log 某文件
git blame 某文件

分支和标签

创建新分支

git branch 新分支
git branch 新分支 已有分支
git branch 新分支 某个commit的id
git chechout -b 新分支

列出分支

git branch -v
git branch -av
git branch -rv
git branch -rv -l '某样式'

删除分支

git branch -d 要删除的分支
git branch -D 要删除的分支
git branch --merged master | grep -v '^\*\ | master ' | xargs -n 1 git branch -d
git remote prune origin

打标签

git tag 标签名 (commit的id)

两分支之间的集合

git merge A分支
git merge A分支 B分支
git rebase B分支
git rebase B分支 A分支
git mergetool

远端交互

git remote -v
git remote add url地址
git remote remove (remote的名称)
git remote rename 旧名称 新名称
git fetch remote
git pull remote名称 分支名
git push remote名称 分支名
git push remote --delete 远端分支名
或者
git push remote:远端分支名
git push remote 标签名
git push remote --tags
上一篇 下一篇

猜你喜欢

热点阅读