git应用入门

1 篇文章 0 订阅

安装配置

$ git config --global user.name "Your Name"
$ git config --global user.email your.email@example.com

 

使用co作为checkout的alias

$ git config --global alias.co checkout

 
设置git的默认编辑器

$ git config --global core.editor "subl -w"

 
Replace "subl -w" with "mate -w" for TextMate, "gvim -f" for gVim, or "mvim -f" for MacVim.

初始化git空文件夹

$ git init

 
Initialized empty Git repository in /Users/mhartl/rails_projects/first_app/.git/

配置rails命令生成的.gitignore文件


# Ignore bundler config
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

 

Mac OS 如此配置

# Ignore bundler config
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

# Ignore other unneeded files.
doc/
*.swp
*~
.project
.DS_Store

 

add和commit

$ git add .

 
查看状态

$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#       new file:   README.rdoc
#       new file:   Rakefile
...

 


提交命令

$ git commit -m "Initial commit"
[master (root-commit) df0a62f] Initial commit
42 files changed, 8461 insertions(+), 0 deletions(-)
create mode 100644 README.rdoc
create mode 100644 Rakefile

 
(-m让你添加一条提交信息)

查看git日志

$ git log
commit df0a62f3f091e53ffa799309b3e32c27b0b38eb4
Author: Michael Hartl <michael@michaelhartl.com>
Date:   Thu Oct 15 11:36:21 2009 -0700

  Initial commit
...
 

关于回滚
$ git checkout -f
$ git status
# On branch master
nothing to commit (working directory clean)
$ ls app/controllers/
application_controller.rb
 
(-f强制重写当前改变)

关于同步到远程github
$ git remote add origin git@github.com:<username>/first_app.git
$ git push origin master
 
关于git的分支
$ git checkout -b modify-README
Switched to a new branch 'modify-README'
$ git branch
master
* modify-README
 
(使用checkout的-b创建分支,git branch查看当前所有的分支,*说明当前的分支
git checkout -b modify-README创建分支并转换到当前分支

关于git的编辑功能
$ git mv README.rdoc README.md
$ subl README.md
 
mv类似unix的mv

新的README.md
# Ruby on Rails Tutorial: first application

This is the first application for
[*Ruby on Rails Tutorial: Learn Rails by Example*](http://railstutorial.org/) 
by [Michael Hartl](http://michaelhartl.com/).

$ git status
# On branch modify-README
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    README.rdoc -> README.md
#
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   README.md
#
 

提交
$ git commit -a -m "Improve the README file"
2 files changed, 5 insertions(+), 243 deletions(-)
delete mode 100644 README.rdoc
create mode 100644 README.md
 
(-a提交所有改变)

关于合并Merge
$ git checkout master
Switched to branch 'master'
$ git merge modify-README
Updating 34f06b7..2c92bef
Fast forward
README.rdoc     |  243 --------------------------------------------------
README.md       |    5 +
2 files changed, 5 insertions(+), 243 deletions(-)
delete mode 100644 README.rdoc
create mode 100644 README.md
 

合并了所有changes后可以执行以下命令
$ git branch -d modify-README
Deleted branch modify-README (was 2c92bef).
 
用以删除合并了的分支,这步可选

# For illustration only; don't do this unless you mess up a branch
$ git checkout -b topic-branch
$ <really screw up the branch>
$ git add .
$ git commit -a -m "Major screw up"
$ git checkout master
$ git branch -D topic-branch
 
使用git branch -D 遗弃分支
(与-d不同,-D可以删除没有合并过的分支)

关于push
$ git push
 
在大多数系统上可以省略origin master直接使用git push
在某些系统上会出现问题
$ git push
fatal: The current branch master is not tracking anything.
 






 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值