GIT基本操作命令

原文地址:http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html

整理了原文前半部分的常用命令。关于多人协作方面的命令待有空了再整理。

[code language="powershell"]
#设置用户名称和邮件地址
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com

#导入一个已经存在的项目(以tar.gz打包)
$ tar xzf project.tar.gz
$ cd project
$ git init

#添加(所有)文件到git管理(注意后面的.)
$ git add .

#添加某几个文件
$ git add file1 file2 file3

#查看已有的修改(如果不使用 --cached,git diff将显示所有不包含于未添加到索引的文件修改)
$ git diff --cached

#使用如下的命名查看修改概略(即那些文件变动了,但是不包含变动的内容)
$ git status

#提交
$ git commit

#添加所有未添加的文件,并提交
$ git commit -a

#提交同时添加说明(少于50个字符)
$ git commit -m “message”

#查看日志
$ git log

#查看每一步的详细修改日志
$ git log -p

#日志摘要
$ git log --stat --summary

#创建一个新的分支(名称为“experimental”)
$ git branch experimental

#列出所有分支名称(分支名称前带“*”的是当前使用的分支)
$ git branch

#切换到指定分支
$ git checkout experimental

#将指定的分支合并到当前使用的分支
$ git merge experimental

#以图形化的界面显示历史记录(会启用GUI界面,不知道存命令模式下会怎么样)
$ gitk

#删除一个分支(仅在分支的内容已经被合并到当前分支的情况下才会执行)
$ git branch -d experimental

#强制删除一个分支(不管有没有被合并)
$ git branch -D crazy-idea

#克隆分支
bob$ git clone /home/alice/project myrepo

#获取并合并其他人的分支(将Bob的master分支合并到Alice的当前分支下,如果Alice已经有改动,则需要手动合并)
alice$ git pull /home/bob/myrepo master
[/code]

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Hello world

Hi,我是Tang Bin,finalbug.org是我的个人站点。这里有更多关于我的内容。English readers please click here to learn more about me and this site.

Categories