git的简单使用

git是一个让人特别兴奋的神器。神在哪,不解释!
git add fileName : 添加修改到暂存区。
git commit -m "discription". 提交到仓库
git push push到远端仓库
git log 查看历史版本
git reflog 查看提交历史
git checkout 一键还原(没有push到远端的情况下)到上一级。到底几级呢?我的理解是四级:1,工作区。2,stage。3,master。4,远端。
git status 当前工作区状态。
git是跟踪修改的,不是跟踪文件的。修改包括:增删改查
git rm :删除文件。前提是在branch或者stage中的文件
git remote add origin git@github.com:userAccount/repo-name.hit 与远程仓库连接
git push -u origin master push到远端什么呢?master
git clone git@github.com:userAccount/target.git
git支持多种协议,默认使用git协议,当然http和https也是支持的。
git branch bName 创建一个叫bName的分支
git checkout bName 切换分支到bName
git branch 查看当前分支
git merge bName 合并分支。(faster forward其实只是修改了master的指向合并)此命令是将指定branch合并到当前branch
git branch -d dev删除指定分支
git log --graph 查看分支合并图
git stash 保护当前工作现场
git stash list stash列表
git stach apply 恢复工作现场 但是没有删除记录
git stach drop 删除stash
git stash pop 恢复并且删除
多人协作:
git push origin branchName 推送自己的修改
git pull 如果推送失败是因为远端分支比本地更新,git pull来试图合并 git pull 抓取分支
如果合并有冲突则先解决冲突并在本地提交
在git pull的时候提示 no tracking information 说明本地分支没有和远端分支建立连接 git branch --set-upstream branchName origin/branchName 建立连接
查看远端仓库信息:git remote -v
在本地创建和远端一致的分支 git branch -b branchName origin/branchName

在此万分感谢,git教程By廖雪峰的作者廖雪峰。以上笔记都是出自此教程,本人测试均无误。

原文地址:https://www.cnblogs.com/huaziWEB/p/4455782.html