基本用法
1、拉取代码
git clone [地址]
2、更新代码
git pull
3、查看分支
git branch #查看当前分支
git branch -a #查看所有分支
4、切换分支
git checkout [分支名]
5、提交代码
git add [文件名] / git add -A [文件夹名]
git commit -m '[注释]'
git push
6、查看提交记录
git log
有点复杂的用法
1、版本回退
git reset --hard HEAD^ #回退一版
git reset --hard [id] #回退到指定版本
2、git add 后撤销
git reset HEAD #撤销上一次全部的add
git reset HEAD [文件名] #撤销某个add的文件
3、git push后撤销(注:会有撤销记录)
git revert [id] #id为要撤销的之前的id
git push
4、A分支中的某个修改合入另一个(B)分支
#1.先在A分支下git pull,当前A分支是最新的
#2.切换到B分支,git pull,保证B分支是最新的
#3.
git cherry-pick [id] #id为要合入的修改的id
git push
5、打tag
git tag [tagName] #使用git tag -a [tagname]可以填写注释
git push origin [tagName]
6、git commit 后要add新文件到此commit中
参考:https://www.jianshu.com/p/26dcde1063b6
git add [文件名]
git commit --amend
7、git commit后撤销
参考:https://www.jianshu.com/p/a9f327da3562
git reset --soft HEAD^ #不删除工作空间的改动代码,撤销commit,不撤销git add
git reset --hard HEAD^ #删除工作空间的改动代码,撤销commit且撤销add