zoukankan      html  css  js  c++  java
  • [git]Git常用命令

    转自http://www.cnblogs.com/idche/archive/2011/07/05/2098165.htmlGIT 

    学习笔记 集中化的版本控制系统 CVCS(Centralized Version Control System) 分布式版本控制系统 DVCS(Decentralized Version Control System) Git 基础要点 http://progit.org/book/zh/ch1-3.html 1:直接快照,而非比较差异 2:近乎所有操作都可本地执行 3:时刻保持数据完整性 (Git 使用 SHA-1 算法计算数据的校验 ,40 个十六进制字符(0-9 及 a-f)组成) 4:多数操作仅添加数据 5:三种状态(已提交(committed),已修改(modified)和已暂存(staged)) GIT安装 http://progit.org/book/zh/ch1-4.html 配置GIT http://progit.org/book/zh/ch1-5.html $ git config --global user.name "John Doe"  //global对所有的repo都有效 $ git config --global user.email johndoe@example.com 查看配置 git config --list 1. GIT 基础 初始化仓库 $ git init $ git add *.c $ git add README $ git commit -m 'initial project version' 从现有仓库克隆 $ git clone git://github.com/schacon/grit.git 仓库状态 $ git status 跟踪新文件 $ git add fileName 忽略某些文件 $ cat .gitignore *.[oa] //忽略以 .o 或 .a 结尾的文件 *~ //忽略所有以波浪符(~)结尾的文件 查看已暂存和未暂存的更新 $ git diff $ git diff --cached //已经暂存起来的文件和上次提交时的快照之间的差异 提交更新 $ git commit -m "message" // 简单的提交方式 $ git commit -a -m "message" // 跳过add 步骤 把已经跟踪的文件全部提交 移除文件 $git rm fileName $ git rm --cached readme.txt //移除跟踪但不删除文件 移动文件 $ git mv file_from file_to 日志 $ git log $ git log –p -2 // -p 提交内容的差异 -2最近两次 $ git log --stat//显示简要的增改行数统计 修改最后一次提交 $ git commit --amend //---第2次提交修改了第一次提交 $ git commit -m 'initial commit' $ git add forgotten_file $ git commit --amend 取消已经暂存的文件 $ git reset HEAD fileName 取消对文件的修改(回退到以前未修改的状态) //很有用 也很危险 $ git checkout -- fileName 2. 远程仓库的使用   查看当前的远程库 $ git remote -v // -v 列出远程地址 添加远程仓库 $ git remote add Name git://github.com/paulboone/ticgit.git 从远程仓库抓取数据 $ git fetch [remote-name] $ git pull// 合并远程的全部分支到本地(不确定) 推送数据到远程仓库 $ git push origin master //推送 origin 到 master 查看远程仓库信息 $ git remote show origin 远程仓库的删除和重命名 $ git remote rename pb paul// pb 改成 paul 分支对应前缀也会发生变化 $ git remote rm paul// 貌似删除
        
         本地分支重命名
         $ git branch -m <old_branch> <new_branch> 3. 打标签 http://progit.org/book/zh/ch2-6.html 列显已有的标签 $ git tag $ git tag -l 'v1.4.2.*'//搜索标签 新建标签 $ git tag -a v1.4 -m 'my version 1.4' //新建v1.4标签 消息是 my version 1.4 分享标签 $ git push origin [tagname] //提交 一个标签 $ git push origin --tags // 推送所有本地标签 删除 $ git tag -d [tagname] //删除标签 $ git push origin :refs/tags/tagname //删除远程标签 4. 技巧和窍门 提示 // 敲两次tab Git 命令别名
         
    $ git config --global alias.co checkout // git co 代替了 git checkout
         $ git config --global alias.st status
         $ git config --global alias.ci commit
         $ git config --global alias.br branch
         $ git config --global alias.unstage reset HEAD --
         $ git config --global alias.last log -1 HEAD
         当然这里最好是通过修改 vi ~/.gitconfig文件,格式如
         [alias]
          st = status
           ..... 5. 分支 创建分支 $ git branch testing // 创建testing $ git checkout testing// 切换到testing $ git checkout -b iss53 //创建并切换到iss53 $ git merge hotfix //把hotfix 分支合并到当前分支 查看分支 $ git branch -v//最后一次commit信息 $ git branch --merged | --no-merged//筛选出你已经(或尚未)与当前分支合并的分支 删除 $ git branch -D testing 推送
         $ git push origin serverfix//把当前推送到 serverfix分支,省略远程分支名,表明当前分支和远程分支存在追踪关系,同样本地分支名也是可以省略的
       $ git push <远程主机名> <本地分支名>:<远程分支名>  //和pull相反, git pull <远程主机> <来源地_远程分支名>:<目的地_本地分支名>
         更新同步 $ git fetch 

         删除远程分支 git push origin :branchname git branch –r //查看所有分支信息 //获取远端分支 $ git checkout -b sf origin/serverfix

    6. 服务器上的GIT ---http://progit.org/book/zh/ch4-3.html

    生成 SSH 公钥 ---http://github.com/guides/providing-your-ssh-key。 $ cd ~/.ssh //公钥的位置 $ ls authorized_keys2 id_dsa known_hosts config id_dsa.pub $ ssh-keygen //如果上面看不到公钥 可以用次来创建 会要求输入存放位置 和密码

    7. 储藏 $ git status //储藏 $ git stash list//储藏列表 $ git stash apply//应用储藏
    参考资料 http://zh.wikipedia.org/wiki/Git http://progit.org/book/zh/
  • 相关阅读:
    element ui 表单清空
    element ui 覆盖样式 方法
    element ui 修改表单值 提交无效
    element ui 抽屉里的表单输入框无法修改值
    element ui 抽屉首次显示 闪烁
    css 左侧高度 跟随右侧内容高度 自适应
    PICNUF框架
    elementui 抽屉组件标题 出现黑色边框
    vue 子组件跨多层调用父组件中方法
    vue 编辑table 数据 未点击提交,table里的数据就发生了改变(深拷贝处理)
  • 原文地址:https://www.cnblogs.com/aaronLinux/p/5744361.html
Copyright © 2011-2022 走看看