Branch
//查看本地所有分支
git branch
//查看所有分支
git branch -a
//查看分支关联
git branch -vv
//查看分支最后一次提交
git branch -v
//创建分支
git branch [newBranchName]
//切换分支
git checkout [branchName]
//创建并切换到新分支
git checkout -b [newBranchName]
//合并分支
//将branch2分支合并到当前分支(branch1)
git checkout out [branch1]
git merge [branch2]
//拉取(从服务器抓取本地没有到数据)
git fetch
//拉取数据并尝试合并
git pull 等价于 git fetch && git merge
//删除分支
//删除本地分支
git branch -d [branchName]
//强制删除分支
git branch -D [branchName]
//删除远程分支
git push origin -delete [branchName]
//建立当前分支和远程分支关联
git branch -u origin/branchName
//推送当前分支到远程(远程没有则直接新建)
git push origin [branchName]
//重命名本地分支
git branch -m [oldBranchName] [newBranchName]
//修改远程分支名
git branch -m [oldBranchName] [newBranchName]
git push origin --delete [oldBranch]
git push origin [newBranchName]
git branch -u origin/newBranchName
//拣选工作流
//用来获得在单个提交中引入的变更,然后尝试将作为一个新的提交引入到你当前分支上
git cherry-pick commit-hash
//提交
git commit -m "commit info"
//如果嫌每次commit都要先git add麻烦可以这样
git commit -am "commit info"
Log
//查看最近二次差异
git log -p -2
回滚
// 场景1: 该乱了某个文件,想丢弃工作区的内容
git checkout -- file
// 场景2:该乱了某个文件内容,且添加到暂存区;想丢弃修改;
// 分二步走; 1使用下面
git reset HEAD <file>
恢复到场景1,之后走场景1流程
// 场景3:该坏了文件,且已经commit了还未push
// 前提是没有push到远程
// 回滚到上次提交版本
git reset --hard HEAD^
git reset --hard commit-id
//回滚指定文件到指定版本
//1. 查看文件修改记录
git log fileName
//记录太多可以使用-number过滤
git log -number fileName
//2. 回退
git reset commit_hash fileName
//3. commit
git commit -m "reset code because xxxx"
//4. 更新工作目录
git checkout fileName
//5. push to remote
git push origin remoteBranch
//如果本地分支和远程分支关联直接使用
git push
//此为默认方式,不带任何参数的git reset,这种方式,它回退到某个版本,只保留源码,回退commit和index信息
git reset -mixed
//回退到某个版本,只回退了commit的信息,不会恢复到index file一级。如果还要提交,直接commit即可
git reset -soft
//彻底回退到某个版本,本地的源码也会变成为上一个版本的内容
git reset -hard
Tag
//列出tag
git tag
//搜索符合指定条件tag
git tag -l 'v1.8.5*'
//显示tag信息
git show v1.1
//新建附注tag
git tag -a v1.1 -m 'some info'
//后期打tag
git tag -a v1.1 9fceb02(commit hash)
//共享tag
//推送指定tag
git push orign [tagName]
//推送多个
git push origin --tags
//检出tag
git checkout -b [brancnName] [tagName]
DIFF
//比较内容
git diff branch1/tag .. branch2/tag
//比较文件名
git diff branch1 .. branch2 --stat
Question
how to change git from chinese to english in mac
export LC_ALL=en_US.UTF-8
Add it to your .bashrc or .zshrc file