sh#git config 用来配置一些基本信息,最经常使用的以下 git config --global user.name "suemi" git config --global user.email suemi94@qq.com git config --global core.editor vim
shellgit remote add origin ssh:....#增长远程仓库origin,远程仓库名为origin时能够不带 git remote #查看有哪些远程仓库
shellgit branch #查看本地分支 git branch -r origin #查看远程仓库分支 git branch -d work#删除work分支 git branch jj#新建本地jj分支 git checkout work#切换到本地work分支 git checkout
这个没什么好说的,用的太多了git
shellgit pull origin work:master#拉取远程仓库origin的work分支到本地的master分支上,通常用于别人提交了后使用 git fetch origin work # 拉取远程仓库origin的work分支 git diff origin/work..master #查看两分支的差别 git merge origin/work#在当前分支上合并origin/work
shellgit push origin master:work#推送本地master分支到远程仓库origin的work分支上 gut push origin :work#删除远端的work分支 git push -f 强制push,哪怕远程分支的commit记录比你新
shellgit commit -a -m "first commit" #操做文件 git commit --amend#将以后的操做补上去,最终只提交了一次
shellgit status#查看当前状态
shellgit dff#显示尚未保存的改动 git diff --cached#显示已经保存和最近提交之间的差别
shellgit revert 會用一個新的 commit 來回復全部的變更(適合已經push出去給別人的情境)。 git revert HEAD#撤销前一次提交 git revert HEAD^#撤销前前次提交 git revert 5962845b0059f9e7702b73066e6a35aea1efaa49#撤销特定某次提交 git reset HEAD^ 就會回到前一版本,適合發現前一次 commit 有問題或是想要修改 commit log,能够修改後再从新 commit。你在文件所作的修改下次依然会提交 git reset –hard HEAD^ 則會彻底抹掉前一次的 commit。 git rebase 会直接从新构建你的commit history,不推荐使用
最后,小提醒:工做以前先看看别人有没有提交,push以前看看有没有更新,优先推荐git fetch,还有在push以后就不要使用commit --amend了shell
注意:你想push的分支绝对不能有你本地所没有的commit,也不能有与本地分支记录不一致的commit
详细解释能够参考Git 初学指南vim