码迷,mamicode.com
首页 > 其他好文 > 详细

Git基础篇【转】

时间:2017-02-28 00:51:42      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:crlf   hello   blank   mat   check   alias   日志   move   ace   

 

转自: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."

Git基础篇【转】

标签:crlf   hello   blank   mat   check   alias   日志   move   ace   

原文地址:http://www.cnblogs.com/sky-heaven/p/6476871.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!