Git入门笔记

Github 为例
最新版:https://www.zybuluo.com/c-Ku/note/808925

配置好后:

右上角头像旁边 ➕下拉点击「New repository」创建新仓库
然后在需要上传的文件夹下打开终端 并依次输入以下指令

$ git init                      // 初始化
$ git add .                     // 添加文件到暂存区
$ git commit -m "rd-0.0.1"      // 添加到仓库 双引内为版本号

$ git remote add origin https://github.com/用户名/仓库名.git
// 指定远程仓库
$ git push -u origin master     // 推到master分支上

使用 fetch 命令进行合并

git fetch [<options>] [<repository> [<refspec>…]]
git fetch [<options>] <group>
git fetch --multiple [<options>] [(<repository> | <group>)…]
git fetch --all [<options>]

比如 git fetch origin master 使用该命令 取回 origin 主机的 master 分支

所取回的更新,在本地主机上要用”远程主机名/分支名”的形式读取。比如origin主机的master分支,就可以用origin/master读取。

git branch命令的-r选项,可以用来查看远程分支,-a选项查看所有分支。

$ git branch -r
origin/master

$ git branch -a
* master
  remotes/origin/master

最后需要在本地分支上通过以下命令合并本地的远程仓库

$ git merge origin/master
# 或者
$ git rebase origin/master

然后可以看到相对应的改变

$ git branch -a
# 查看所有分支
$ git checkout "分支名"
# 切换到分支
$ git checkout -b "分支名"
# 新建并切换到分支
$ git merge "分支名"
# 合并临时分支

$ git reflog
# 獲取全部commit版本log
$ git reset --hard "接需要回滾的版本號"
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容