• Git基础篇【转】


     

    转自:https://i.cnblogs.com/EditPosts.aspx?opt=1

    1.设置名字与邮箱

    Git config –global user.name “YourName”

    $ git config –global user.email your_email@whatever.com

    2.设置换行符

    git config --global core.autocrlf input

    git config --global core.safecrlf true

    3.初始化一个工程

    $ mkdir hello

    $ cd hello

    $ git init

    4.在工程目录中加入文件

    $ git add hello.rb

    $ git commit -m "First Commit"

    5.查看当前状态

    $ git status

    6.查看日志文件

    $ git log

    7.每个记录的日志在一行内显示

    git log --pretty=oneline

    8.设置别名

    HOME目录下的.gitconfig

    [alias]

      co= checkout

      ci= commit

      st= status

      br= branch

     hist = log --pretty=format:"%h %ad | %s%d [%an]" --graph--date=short

     type = cat-file -t

     dump = cat-file –p

    9.将checkout point指向最新的分支

    git checkout master(最近的分支)

    10.为当前状态设置标签

    git tag v1

    11.checkout point指向v1的上一个版本

    git checkout v1^(表示v1的上一个版本)

    12. 查看当前的所有tag

    git tag

    13.设置一种输出格式

    Hist log --pretty=format:"%h %ad |%s%d [%an]" --graph --date=short

    Head表示当前的check out commit

    14.当对一个文件做了改变,但是还没有staging,可以使用git checkout file来忽略对文件的改变:

    git checkout hello.rb

    git status

    cat hello.rb

    15.当对一个文件做了改变,已经staging,但是没有committing,想恢复时,首先reset到staging前的状态,再使用checkout到原始状态:

    git reset HEAD hello.rb

    git checkout hello.rb

    16.当对一个文件做了改变,已经committing,想恢复时,首先revert,然后reset到staging前的状态,再使用checkout到原始状态:

    git revert HEAD

    git reset --hard v1(hard指定最近的那个分支)

    git tag -d oops

    17. 修正刚才的commit

    git commit --amend -m "Add anauthor/email comment"

    18.移动文件夹,将文件夹移动到另外一个目录时:

    A.

    mkdir lib

    git mv hello.rb lib

    git status

    git commit -m "Moved hello.rb tolib"

    B.

    mkdir lib

    mv hello.rb lib

    git add lib/hello.rb

    git rm hello.rb

    git commit -m "Moved hello.rb tolib"

    19.新增文件到repository

    git add Rakefile

    git commit -m "Added a Rakefile."

  • 相关阅读:
    98.公共汽车
    100.选菜(动态规划)01背包
    102.愤怒的LJF
    96.老鼠的旅行(动态规划)
    95.(01背包)之小吃
    94.Txx考试
    93.数字三角形W(深搜)
    POJ 3352 Road Construction (边双连通分量)
    POJ 3114 Countries in War(强联通分量+Tarjan)
    POJ 3592 Instantaneous Transference(强联通分量 Tarjan)
  • 原文地址:https://www.cnblogs.com/sky-heaven/p/6476871.html
Copyright © 2020-2023  润新知