git命令总结
git命令图解:
命令速查:
版本控制(实用建议)
Ref: https://www.git-tower.com/blog/git-cheat-sheet-cn
Ref: https://www.jianshu.com/p/2bdd4b150905
1.获取代码
1.1克隆远程仓库代码
git clone https://gitee.com/tianyac/test.git
1.2下拉代码
git pull
2.分支
2.1创建分支
git branch csj
2.2切换分支
git checkout csj
2.3新建并切换到新分支
git checkout -b csj
3.提交代码
git add . //提交到暂存区(index)
git commit -m '提交信息' //将暂存区的所有修改提交到本地仓库(local repository)
git push 将本地仓库代码提交到远程分支(remote repository)
4.冲突解
4.1使用stash解决
通过git stash命令,把工作区的修改保存到栈区(该空间可跨分支访问);
通过git pull命令,拉取远程分支上的代码并合并到本地分支;
通过git stash pop命令,把保存在栈区的修改部分合并到最新的工作空间中,git会自动标记出有冲突的地方,然后手动选择保留本地修改还是保留远程修改;
4.2更多stash命令
-
git stash [save message]
保存,save
为可选项,message
为本次保存的注释 -
git stash list
所有保存的记录列表 -
git stash pop [email protected]{num}
恢复,num
是可选项,通过git stash list
可查看具体值。只能恢复一次 -
git stash apply [email protected]{num}
恢复,num
是可选项,通过git stash list
可查看具体值。可恢复多次 -
git stash drop [email protected]{num}
删除某个保存,num
是可选项,通过git stash list
可查看具体值 -
git stash clear
删除所有保存