Git常用命令 shuo

记录一下工作中常用的git命令,不定期更新。

设置vim为git的默认编辑器

git config --global core.editor "vim"

克隆repo的特定branch

git clone -b branch-name repo.git

按照文件显示diff

git diff commit1 commit2 --stat

变基,一般用来合并多个commit

git rebase -i HEAD~4

撤销所有暂存的文件

git reset HEAD .

撤销某个暂存的文件

git reset HEAD -- filename

撤销某一次commit

git revert commit

暂时保存工作

git stash

使用某次暂存的代码

git stash apply stash@{1}

添加上游仓库

git remote add upstream repo.git

取消追踪某个文件

git rm -r --cached filename

-r表示递归模式,--cached只会在索引中移除文件,不会删除文件

同步上游仓库的代码

git fetch upstream
git checkout master
git merge upstream/master

本文来自博客园,作者:shuo-ouyang,转载请注明原文链接:https://www.cnblogs.com/shuo-ouyang/p/13468807.html

原文地址:https://www.cnblogs.com/littleorange/p/13468807.html