Git使用说明

Git使用说明

      • 一、配置
      • 二、使用
      • 三、GitHub

一、配置

  • -1.SSH认证

    说明:SSH 为 Secure Shell的缩写,SSH最初是UNIX系统上的一个程序,后来又迅速扩展到其他操作平台。

    为了在不同平台/网络主机之间的通信安全, 很多时候我们都要通过ssh进行认证。

    ssh认证方式主要有2种:

    ① 基于口令的安全认证: ssh [用户名]@[IP],每次输入口令(中间人攻击);

    ② 基于密钥的安全认证: 传输一次公钥,免密登录。Git的ssh方式就是通过公钥进行认证的。

  • 0.检查是否已经有 SSH key

    cd ~/.ssh
    # 检查是否已经存在 id_rsa(私钥) 和 id_rsa.pub(公钥) 文件。(可信服务器:known_hosts)
    
  • 1.ssh-keygen创建公私钥对

    # -t 指定密钥类型,默认是 rsa ,可以省略。
    # -C 设置注释文字,比如邮箱。
    # -f: 密钥目录位置, 默认为当前用户home路径下的.ssh隐藏目录, 也就是~/.ssh/
    ssh-keygen -t rsa -C "[email protected]" # 全部按enter
    
  • 2.配置全局的name和email

    # 表明这台机器上的所有Git仓库都会使用这个配置。
    git config --global user.name "Your Name"
    git config --global user.email "[email protected]"
    
  • 3.找到客户端公钥

    cd ~/.ssh
    # 查看公钥
    cat id_rsa.pub
    
  • 4.将公钥保存到Git服务端

    复制,打开github ,点击头像 =>> settings =>> SSH and GPG keys =>> New SSH key

二、使用

  • 概括

    fetch/clone
    push
    commit
    add
    pull
    checkout
    Remote
    Repository
    index
    workspace

    git fetch是将远程主机的最新内容拉到本地,用户在检查了以后决定是否合并到工作本机分支中。

    git pull 是将远程主机的最新内容拉下来后直接合并,即:git pull = git fetch + git merge,这样可能会产生冲突,需要手动解决。

  • 常用命令

    # 查看状态gst = git status
    git status
    # 将服务器内容拉到本地仓库
    git fetch
    # 切换到master分支
    git checkout master
    # 将dev分支合并到当前分支(master)中
    git merge dev
    # 比较workspace和Repository差异
    git diff
    # 查看本地所有分支
    git branch
    # 查看远程所有分支
    git branch -r
    # 查看本地和远程的所有分支
    git branch -a
    # 提交到本地
    git commit -m "message"
    # 提交到服务器
    git push
    # 可以查看所有分支的所有操作记录(包括已经被删除的 commit 记录和 reset 的操作)
    git reflog
    # 不能查看已经删除了的commit记录
    git log
    
  • Git快捷命令

    g - git
    gst - git status
    gl - git pull
    gup - git pull --rebase
    gp - git push
    gd - git diff
    gdc - git diff --cached
    gdv - git diff -w "$@" | view
    gc - git commit -v
    gc! - git commit -v --amend
    gca - git commit -v -a
    gca! - git commit -v -a --amend
    gcmsg - git commit -m
    gco - git checkout
    gcm - git checkout master
    gr - git remote
    grv - git remote -v
    grmv - git remote rename
    grrm - git remote remove
    gsetr - git remote set-url
    grup - git remote update
    grbi - git rebase -i
    grbc - git rebase --continue
    grba - git rebase --abort
    gb - git branch
    gba - git branch -a
    gcount - git shortlog -sn
    gcl - git config --list
    gcp - git cherry-pick
    glg - git log --stat --max-count=10
    glgg - git log --graph --max-count=10
    glgga - git log --graph --decorate --all
    glo - git log --oneline --decorate --color
    glog - git log --oneline --decorate --color --graph
    gss - git status -s
    ga - git add
    gm - git merge
    grh - git reset HEAD
    grhh - git reset HEAD --hard
    gclean - git reset --hard && git clean -dfx
    gwc - git whatchanged -p --abbrev-commit --pretty=medium
    gsts - git stash show --text
    gsta - git stash
    gstp - git stash pop
    gstd - git stash drop
    ggpull - git pull origin $(current_branch)
    ggpur - git pull --rebase origin $(current_branch)
    ggpush - git push origin $(current_branch)
    ggpnp - git pull origin $(current_branch) && git push origin $(current_branch)
    glp - _git_log_prettily
    

三、GitHub

  • 本地项目上传到GitHub
IDEA
VCS
Import into Version Contral
Share Project on GitHub

你可能感兴趣的:(项目管理,git,ssh,github)