• git常用命令


    对git的命令进行了个简单的总结,以防忘记某个命令的时候回来找找。

    git config:列出config命令下的子命令

    git config global user.name "":设置全局变量user.name

    git config global user.email "";设置全局变量user.email

    git config -l或者git config --ls:列出config下已经设置好的变量

    git log:查看当前仓库的历史纪录

    git status:查看当前working directory的状态

    git status -s:简化的git status命令

    git的三个状态:

    git add hello.py:将 hello.py从working directory提交到staging area.

    git clone http://:

    git rm hello.py:删除working directory与staging area中hello.py文件。

    git rm --cached hello.py:删除staging area中hello.py文件。注:staging area 也叫cache或者index

    git mv hello.py hello.txt:重命名working directory与staging area中hello.py文件。相当于下面三个操作:

    git rm --cached hello.py -> mv hello.py hello.txt -> git add hello.txt

    git commit -m '':提交staging area到repository(history)。

    git commit -am '':提交working directory到staging area和repository(history)。

    git stash:将当前杂乱的working directory中的文件放到 抽屉中,后期可以取出来进行展开。注:这时,working directory,staging area与repository(history)保持一致,还原到最初的状态。

    git stash list:将被放到 抽屉 中的working directory列出来。

    git stash pop:展开 抽屉 中的working directory,恢复到 抽屉 中的working directory状态。

    git diff:查看working directory与staging area的区别。

    git diff --staged:查看staging area与repository(history)的区别。

    git diff HEAD:working directory与repository(history)的区别。

    git diff --stat HEAD:对命令git diff HEAD进行简化

    git reset hello.py:用repository(history)的文件来覆盖staging area的文件,达到回滚staging area的目的。

    git checkout hello.py:用staging area的文件来覆盖working directory的文件,达到回滚working directory的目的。

    git checkout HEAD hello.py:用repository(history)的文件来覆盖working directory的文件,达到回滚working directory的目的。

    git commit -a -m 'add file' hello.py或者git commit -am 'add file' hello .py:从working directory直接提交到 repository(history)。注:hello.py必须已经受版本控制的文件,即在之前此文件已经进行过git add的操作。

    下面的命令是针对 history(repository)区域的:

     history(repository)区域存储的是n个commit对象,每个commit对象又包含两部分,1.tree:此版本下的所有文件,以树的形式,2.parent:指针,指向前一个commit对象。

    git cat-file -t HEAD(也可以是commit对象的hashcode):列出HEAD指向的commit对象。即查看HEAD的类型

    git cat-file -p HEAD(也可以是commit对象的hashcode):直接打开HEAD指向的commit对象。

    git log --oneline:输出git的日志,每次改动以一行的形式。

    git rev-parse HEAD:查看HEAD指向的hash码。

    git rev-parse HEAD~4:查看从HEAD开始(不包含HEAD),倒数第4个指向的hash码。

    git rev-parse master~4:查看从HEAD开始(不包含HEAD),倒数第4个指向的hash码。与  HEAD~4 相同

    git rev-parse HEAD~4^{tree}:查看HEAD~4中,第一个tree的hashi值。

    git rev-parse HEAD~4:hello.py:查看HEAD~4中,hello.py的hashi值。

    git cat-file -p HEAD~4:hello.py:  查看HEAD~4中,hello.py的内容。

    git show HEAD~4:hello.py: 查看HEAD~4中,hello.py的内容。等同于上一个命令。

    查看history中的命令,叫做tree-ish.

    分支相关:

    git branch:查看当前仓库的分支。

    git branch b1:创建一个名字叫b1的新分支。

    git checkout b1:将当前工作的master分支切换到b1.

    git checkout -b b1:创建一个名字叫b1的新分支并且切换到此分支下。

    git branch -d b1:删除b1分支。

    git merge b1:将b1合并到master分支上

    分支相关目录:仓库下面,.git/HEAD,  .git/refs/master。

    待续---

  • 相关阅读:
    使用 VBRichClient 库
    提取文件夹目录的办法
    编程语言转换
    解决linux服务器上matplotlib中文显示乱码问题
    动态规划 53:Maximum Subarray,152:Maximum Subarray,266. Palindrome Permutation 回文全排列
    动态规划:494,576
    ResourceExhaustedError 解决方案
    周赛138场
    leetcode 115
    leetcode 372
  • 原文地址:https://www.cnblogs.com/westward/p/5770846.html
Copyright © 2020-2023  润新知