[关闭]
@c-Ku 2018-05-25T10:16:06.000000Z 字数 2149 阅读 662

Git入门笔记

Git cNotes


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

没配置前:


配置好后:

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

  1. $ git init // 初始化
  2. $ git add . // 添加文件到暂存区
  3. $ git commit -m "rd-0.0.1" // 添加到仓库 双引内为版本号
  4. $ git remote add origin https://github.com/用户名/仓库名.git
  5. // 指定远程仓库
  6. $ git push -u origin master // 推到master分支上

使用 fetch 命令进行合并

  1. git fetch [<options>] [<repository> [<refspec>…]]
  2. git fetch [<options>] <group>
  3. git fetch --multiple [<options>] [(<repository> | <group>)…]
  4. git fetch --all [<options>]

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

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

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

  1. $ git branch -r
  2. origin/master
  3. $ git branch -a
  4. * master
  5. remotes/origin/master

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

  1. $ git merge origin/master
  2. # 或者
  3. $ git rebase origin/master

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

  1. $ git branch -a
  2. # 查看所有分支
  3. $ git checkout "分支名"
  4. # 切换到分支
  5. $ git checkout -b "分支名"
  6. # 新建并切换到分支
  7. $ git merge "分支名"
  8. # 合并临时分支
  9. $ git reflog
  10. # 獲取全部commit版本log
  11. $ git reset --hard "接需要回滾的版本號"
  12. $ git push --set-upstream origin test
  13. $ git branch -d test
  14. $ git push origin --delete test
  15. $ glg // 输出log
  16. $ git reset HEAD^ // 重设
  17. $ gcb reset-name

如何上手配置

  1. USER git config --global user.name "c-Ku"
  2. USER git config --global user.email "chyhoosun@gmail.com"
  3. USER ssh-keygen -t rsa -C "chyhoosun@gmail.com"
  4. Generating public/private rsa key pair.
  5. Enter file in which to save the key (/Users/6ml/.ssh/id_rsa):
  6. Created directory '/Users/6ml/.ssh'.
  7. Enter passphrase (empty for no passphrase):
  8. Enter same passphrase again:
  9. // 上面连着三个回车
  10. Your identification has been saved in /Users/6ml/.ssh/id_rsa.
  11. Your public key has been saved in /Users/6ml/.ssh/id_rsa.pub.
  12. The key fingerprint is:
  13. SHA256:DuNkVHwSyBJKRsmPaOsct8DWTgsXSOoiKXxLRHsFUbA chyhoosun@gmail.com
  14. The key's randomart image is:
  15. +---[RSA 2048]----+
  16. | o+..*=+o. |
  17. | +oo. +oo . |
  18. |o.+o.Eo o |
  19. |oo.+.o |
  20. |=.+ o = S |
  21. |=X B + + |
  22. |B @ + . . |
  23. | o = |
  24. | |
  25. +----[SHA256]-----+
  26. ➜ USER eval "$(ssh-agent -s)"
  27. Agent pid 5982
  28. ➜ USER ssh-add ~/.ssh/id_rsa
  29. Identity added: /Users/6ml/.ssh/id_rsa (/Users/6ml/.ssh/id_rsa)
  30. ➜ USER ssh -T git@github.com
  31. The authenticity of host 'github.com (52.74.223.119)' can't be established.
  32. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
  33. Are you sure you want to continue connecting (yes/no)? yes
  34. Warning: Permanently added 'github.com,52.74.223.119' (RSA) to the list of known hosts.
  35. Permission denied (publickey).

最后把 id_rsa.pub 里面的东西复制粘贴过去就好了

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注