美文网首页
GIT的基本指令

GIT的基本指令

作者: 一人一心 | 来源:发表于2018-12-24 15:38 被阅读4次

1. git init

  在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo,并在当前folder下创建一个.git folder。

2. git config

git config --list #查看配置信息
git config --global user.name name  #用户名
git config --global user.email email   #用户邮箱

3. git clone url [alias]

  获取一个url对应的远程Git repo, 创建一个local copy。

4. git status

  查看当前代码库的状态。

5. git add

git add [path] #会把对应目录或文件,添加到stage状态
git add .  #会把当前所有的untrack files和changed but not updated添加到stage状态

6. git commit

git commit -m "message" #提交修改,添加注释

7. git diff

git diff #默认查看工作区和暂存区的区别
git diff --cache #是工作区(work dict)和暂存区(stage)的比较

8. git checkout filename

git checkout filename #从索引中恢复
git checkout branchname #切换分支
git checkout -b branchname #切换到新建分支

9. git branch

9.1 创建分支
git branch newbranch #创建新分支,创建分支但依然停留在当前分支
9.2 删除分支
git branch -d branchname #删除本地分支
git branch -D branchname #新分支还没有合入当前分支,所以要用-D参数才能删掉
git push origin --delete test #删除远程test分支
git push origin :test #删除远程test分支
9.3 查看分支
git branch  #列出当前分支清单
git branch -a #列出所有分支
git branch -r #列出所有远程分支
git branch --merged #查看哪些分支已经合并入当前分支

10. git pull

  git pull取回远程主机某个分支的更新,再与本地的指定分支合并。
  git pull等价于git fetch + git merge

git pull <远程主机名> <远程分支名>:<本地分支名>

11. git reset

git reset --soft #将HEAD引用指向给定提交。索引和工作目录的内容是不变的。
git reset --hard #HEAD引用指向给定提交,索引内容和工作目录内容都会变给定提交时的状态。也就是在给定提交后所修改的内容都会丢失。

12. git remote

git remote #查看关联的远程仓库的名称
git remote -v #查看关联的远程仓库的详细信息
git remote remove <name> #删除远程仓库的关联
git remote add <主机名> <url> #添加远程仓库的关联
git remote set-url origin <newurl> #使用 git remote set-url 命令,更新远程仓库的 url

13. git stash

git stash #暂存当前修改内容
git stash pop #弹出修改内容

14. oh my zsh

Oh My Zsh is a delightful, open source, community-driven framework for managing your Zsh configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes, and a few things that make you shout...

sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)" #via curl
sh -c "$(wget https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)" #via wget

相关文章

  • git远程仓库关联

    一.GitHub常用指令 git的基本使用指令:git init ...

  • 初识git,用git 上传项目到GitHub

    分享一些git基本指令,不喜勿喷! git的基本使用指令 git init 初始化git仓库 git add . ...

  • Linux和git指令

    git常用指令 1.基本指令 git init —— 新建git仓库git add 文件/文件夹 —— 将...

  • 使用git管理本地和远程分支常用指令

    1 基本操作指令 git branch -a ...

  • 组件化(第一篇)

    组件化 git 常用操作指令 cocoapods的基本使用 cocoapods本地私有库 一、git 常用操作指令...

  • git基本指令

    git 一,创建一个本地代码库 二,分支操作 三,添加/删除文件 四,代码提交 五,查看信息 六,远程同步 七,撤...

  • Git 基本指令

    init 创建新目录或进入目标目录 创建版本库:git init branch 显示本地 branchs :git...

  • Git基本指令

    参考资料 Git Community Book 中文版 Git 易百教程 Git 英文参考资料 有关git的工具有...

  • Git基本指令

    unix思想:没有消息就是好消息,正确提交无反馈。 要提交修改得先用add指令添加到暂存区 基本指令 git in...

  • GIT的基本指令

    1. git init   在本地新建一个repo,进入一个项目目录,执行git init,会初始化一个repo...

网友评论

      本文标题:GIT的基本指令

      本文链接:https://www.haomeiwen.com/subject/lsaakqtx.html