拉取代码
git clone
创建分支
git branch dev
#or
git checkout -b dev
#or
git switch -c dev
切换本地分支
git checkout dev
#or
git switch dev
切换分支并联远程分支
git checkout -b dev origin/dev
# or
git checkout --track origin/dev
查看本地所有分支
git branch
查看远程所有分支
git banach -r
删除本地分支
git branch -d dev
删除远程分支
git push origin -d dev
将代码从工作区添加到暂存区
git add .
查看尚未暂存的更新
git diff
添加提交信息( 注释写错,执行 此时会进入默认 编辑器,修改注释后保存)commit``git commit --amend``vim
git commit -m "xxxx"
推送代码到远程分支
git push origin dev
#强制推送 (常在git rebase 或 git reset 后使用)
git push -f origin dev
拉取远程分支代码
git pull origin dev
合并分支
git merge dev
查看状态
git status
查看提交历史
git log
查看可引用的历史版本记录
git reflog
把本地未提交的分叉提交历史整理成 直线
git rebase origin/dev
回到 执行之前的状态rebase
git rebase --abort
回退版本
#回退指定 commit-id 版本
git reset --hard commit-id
#回退 上一个版本
git reset --soft HEAD^
#or
git reset --soft HEAD~1^
撤销代码
git revert commit-id
修改分支名
# 第一步
git branch -m oldBranchName newBranchName
# 第二步
git push origin :oldBranchName
# 第三步
git push --set-upstream origin newBranchName
查看 配置 git
# 查看全局配置
git config --global --list
# 查看用户名
git config --global user.name
添加用户名
git config --global --add user.name newName
删除用户名
git config --global --unset user.name
修改用户名
git config --global user.name newName
配置 用户名和邮箱
# 用户名
git config --global user.name "Your Name"
# 邮箱
git config --global user.email "email@example.com"
统计代码行数
git ls-files | xargs wc -l