• 学习笔记--Git


    //帮助
    git help <command>
    git <command> --help
    git <command> -h

    //配置
    //用户配置
    git config --global user.name "John Everything"      
    git config --global user.email test@example.com
    //配置级别
    --local 默认,只影响本仓库  (.git/config)
    --global  影响当前用户所有仓库  (~/.gitconfig)
    --system 影响全系统的仓库  (/etc/gitconfig)

    //查看仓库状态
    git status

    //初始化仓库
    git init <path>

    //添加文件到暂存区(使跟踪文件)
    git add <filename>
    //添加忽略文件
    ./gitignore中配置忽略文件

    //删除文件
    git rm --cached  //仅从暂存区删除
    git rm  //从暂存区和工作目录删除
    git rm $(git ls-files --deleted)   //删除所有被跟踪,但在工作目录已被删除的文件

    //提交文件
    git commit -m "initial commit"
    git commit -a -m "initial commit"

    //提交历史
    git log
    git log --oneline
    git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

    //设置命令别名
    git config alias.<shortname> <fullcommand>
    git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

    //查看版本差异
    git diff         //查看工作目录与暂存区的差异
    git diff --cached [<refference>]        //暂存区与某次提交的差异,默认为HEAD
    git diff [<refference>]         //工作目录与某次提交的差异

    //撤销工作目录修改
    git checkout -- <file>
    //撤销暂存区内容
    git reset HEAD <file>
    //撤销全部改动
    git checkout HEAD -- <file>

    //分支操作
    git branch <branchname>           //增加分支
    git branch -d <branchname>            //删除分支
    git branch -v            //显示所有分支信息

    //切换分支
    git checkout <branchname>       //切换到某分支
    git checkout -b <branchname>         //创建并切换到某分支
    git checkout <reference>              //切换到某commit ID
    git checkout -            //切换到上一分支

    //回退到某次提交状态
    git reset --mixed <commitId>       //回退到某提交状态,并恢复暂存区
    git reset --hard <commitId>        //回退到某提交状态,恢复暂存区和工作目录
    git reset --soft <commitId>         //回退到某提交状态,保持暂存区和工作目录不变

    //查看最近提交信息
    git reflog

    //对commitId使用捷径
    A^          //A上的父提交
    A~n         //A之前的第N次提交

    //保存工作目录和暂存区
    git stash save ‘first save’             //保存到stash区,返回干净的暂存区和工作目录
    git stash list          //列出stash区的目录
    git stash apply stash@{0}        //载入stash区的某次存储
    git stash drop stash@{0}         //删除stash区的某次存储
    捷径:stash pop = stash apply + stash drop

    //分支合并
    git merge <branch2>      //在branch1中将branch1和branch2合并
    git merge <branch> --no-ff         //防止使用fast-forward方式的合并

    //查看git信息
    git cat-file -p HEAD         //查看HEAD信息

    //发生冲突时,手动修改文件后进行手动提交
    git add .
    git commit -m 'resolve'

    //修剪提交历史支线,变基
    git rebase master           //使其他分支在master分支上重演,变为线性提交
    git rebase --onto master <commitId>       //选择性地使commitId之后的提交在master上重演

    //使用标签
    git tag v0.1 e39d0b2
    git tag -a 0.1.3 -m “Release version 0.1.3″         //  -a 0.1.3是增加 名为0.1.3的标签,  -m 后面跟着的是标签的注释
    git push origin --tags        //–tags参数表示提交所有tag至服务器端,普通的git push origin master操作不会推送标签到服务器端。
    git tag -d 0.1.3         //删除标签
    git push origin :refs/tags/0.1.3           //删除远端服务器的标签

    //远程连接服务器
    git init ~/git-server --bare          //初始化一个本地的远程服务器,裸仓库,没有工作目录
    git push /users/test/git-server master          //提交到远程服务器
    git push -u origin master           //如果当前分支与多个主机存在追踪关系,则可以使用-u选项指定一个默认主机,这样后面就可以不加任何参数使用Git push
    //配置远程映射
    git remote add origin ~/git-server         //添加一个远程仓库别名
    git remote -v                   //查看远程仓库信息
    //获取远程仓库的提交
    git fetch origin master
    git pull = git fetch + git merge

    //获取获取远程仓库
    git clone = git init + git remote + git pull
    git clone ~/git-server test         //从服务器端将仓库克隆到本地test



  • 相关阅读:
    Vue 消息无缝滚动
    请求不携带cookie问题
    vue中添加favicon
    自定义表单-校验数据规则
    vue 刷新当前页面的方式
    读阮一峰《ECMAScript 6 入门》小结
    Java进阶知识点3:更优雅地关闭资源
    Java进阶知识点2:看不懂的代码
    用Java实现异构数据库的高效通用分页查询功能
    Java进阶知识点1:白捡的扩展性
  • 原文地址:https://www.cnblogs.com/kioluo/p/6860487.html
Copyright © 2020-2023  润新知