Xiaoshier Blog

git 常用命令

git 常用命令

##

分支

创建分支

1
2
3
4
5
6
git checkout -b 'branchName'    // 创建新分支, 并切换至该分支
git branch 'branchName' // 创建新分支
git checkout 'branchName' // 切换分支
git merge 'branchName' // 合并分支
git branch -d 'branchName' // 删除分支
git branch -D 'branchName' // 强制删除分支

远程分支

1
2
3
4
5
6
git ls-remote                   // 查看远程分支
git branch -a // 查看远程分支
git branch 'remote-branch' // 拉取切换分支即可
git pull origin 'localBranch':'remoteBranch' // 拉取远程分支并本地分支关联
git pull origin 'branchName' // 远程分支与本地分支合并
git push --set-upstream origin 'branchName' // 远程创建并推送本地分支

日志

1
2
3
4
5
6
7
8
9
10
11
12
13
git log                                               // commit comment
> commitId, author, date, commit comment

git log -p -3 // file change details
> 显示提交 commit comment, 每个文件的修改详情


git log --stat // commitId, commit file list
> 显示提交 commit comment, 仅显示修改的文件列表


git log --pretty=oneline // commitId, commit comment
> commitId commit comment

储藏

把暂时不想提交的改动保存到一个栈上

1
2
3
4
5
6
7
8
git stash                       
git stash save 'stash-name' // 给当前存储命名
git stash list // 显示 stash 列表
git stash apply // 应用最新的储藏
git stash apply stash@{index} // 应用某一个储藏
git stash drop // 扔掉 stash
git stash drop stash@{index} // 扔掉某一个储藏
git stash branch 'branName' // 从储藏创建一个分支

注释