zoukankan      html  css  js  c++  java
  • Git基本命令总结

    Git是一款免费、开源的分布式版本控制系统。这里总结一下最基本和常用的命令。

    ###本地操作
    1.基础
    git init 创建仓库
    git add <file> 添加文件到暂存区
    git add . 将所有修改过的文件添加到暂存区
    git commit -m <message> 将暂存区的文件提交到版本库
    git rm <file> 从工作区删除文件,并将删除操作提交到暂存区
    git status 查看工作区状态

    2.比较
    git diff <file> 文件在工作区(work-dict)和暂存区(stage)的比较
    git diff --cached <file> 文件在暂存区和分支的比较
    git diff HEAD -- <file> 文件在工作区和分支的比较

    3.历史
    git log 查看提交记录
    git log --pretty=oneline 查看精简提交记录
    git reflog 查看命令历史

    4.回退
    git reset --hard <commit_id> 回退到某个版本
    git checkout -- <file> 丢弃工作区的修改,即返回到最近一次add或commit的状态
    git reset HEAD <file> 丢弃暂存区的修改(unstaged)

    ###远程操作
    1.远程连接
    ssh-keygen -t rsa -C "youremail@example.com" 创建SSH Key
    git remote add origin git@server-name:path/repo-name.git 关联一个远程库(origin为设置的远程库名)
    git push -u origin master 把本地master分支推送到远程,主分支间形成关联
    git clone git@server-name:path/repo-name.git 从远程库克隆到本地(自动形成关联)

    2.本地分支
    git branch 查看分支
    git branch <name> 创建分支
    git checkout <name> 切换分支
    git checkout -b <name> 创建并切换分支
    git merge <name> 合并某分支到当前分支
    git merge --no-ff -m <message> <name> 禁用Fast forword模式的合并,merge时生成新的commit,保留历史分支信息
    git branch -d <name> 删除分支
    git log --graph 查看分支合并图
    git branch -D <name> 强行删除没有合并过的分支
    git stash 储存当前工作现场
    git stash pop 回到工作现场

    3.远程分支
    git remote -v 查看远程库信息
    git checkout -b <branch_name> <origin/branch-name> 在本地创建和远程分支对应的分支
    git branch --set-upstream-to=<origin/branch-name> <branch-name> 建立本地分支和远程的关联
    git push origin <branch_name> 从本地推送分支与远程分支合并
    git pull origin <branch_name> 从远程抓取分支与本地分支合并
    git push 推送所有分支
    git pull 抓取所有分支

    4.标签
    git tag 查看所有标签
    git tag <tag_name> [commit_id] 创建一个标签,默认为HEAD
    git push origin <tag_name> 推送一个本地标签到远程库
    git push origin --tags 推送所有未推送过的标签
    git tag -d <tag_name> 删除一个本地标签
    git push origin :refs/tags/<tag_name> 删除一个远程标签

  • 相关阅读:
    动态传参
    函数的介绍
    文件的操作
    send email with formatted table
    minimize and close window with customed winform
    python algorithm
    something important about docker
    book list
    which language is suitable for what to do
    Find Duplicate Items in list fast
  • 原文地址:https://www.cnblogs.com/zhayujie/p/12941573.html
Copyright © 2011-2022 走看看