Git一些最常用命令

上一篇 / 下一篇  2011-04-07 09:49:35 / 个人分类:Git

最近在学习GIT,发现自己最想用的命令都没有在一个文档里面,我要去好多地方查,在此把最常用的命令做一个搜集。
我使用GIT的目的是管理本地的代码,并没有涉及到多个人操作的情况,所以以下都是最简单的东西.
参考网址:http://os.51cto.com/art/201102/246487.htm

习惯使用5W1H的方法来了解和开展新的任务,这简化成2W1H吧的方法来学习GIT

1. What's Git?
   Git is afree & open source, distributed version control systemdesigned to handle everything from small to very large projects with speed and efficiency.
  Every Git clone is a full-fledged repositorywith complete history and full revision tracking capabilities, not dependent on network access or a central server.Branching and merging are fastand easy to do.
   Git is used for version control of files, much like tools such asMercurial,Bazaar,Subversion,CVS,Perforce, andVisual SourceSafe.

2. Why Git?
  • 总结一下GIT的特色
    • 完全的分布式处理,可以离线提交
    • Git的所有操作几乎不需要网络连接,包括历史回顾,差异显示和提交
    • 同时这也意味着Git会比其它的VCS工具速度更快
  • 参考:
    • http://tech.ddvip.com/2009-12/1261218099141675_2.html
    • http://git-scm.com/
    • http://camel2004juj.blog.163.com/blog/static/354251562010326102858569/

3. How Git works
  • 参考:http://blog.ossxp.com/2010/11/2166/


4. Tutorial
(1). 怎么安装Git?
   我用的是MAC,系统已经自带了GIT,我可以省去安装的这一步了,详细的安装步骤可参见:http://os.51cto.com/art/201101/244064.htm
   不过要想验证GIT是否安装或安装成功了,可以用以下命令:
   git --version
   想查看帮助 git --help <command>
(2). 创建一个本地仓库
  • 创建一个项目目录, mkdir test_project
  • 跳转到这个项目目录下 cd test_project
  • 将该项目的源文件圴放置在此目录下
  • 在当前的目录下创建一个新的空的本地仓库 git init
(3). 提交至暂存区(stage, index)
  • 将该项目所有源文件添加到本地仓库的暂存区 git add .
  • 添加到暂存区的文件相当于被放置到了被跟踪的目录库中,只要这些文件被修改,我们通过, git status 就可以看到有哪些文件发生了变化,继而可以通过(4)来完成提交
   问:修改完了不经过git add 直接提交不可以么?
   答:直接提交是可以的,git commit -a,没有经过git add的文件是不会被跟踪的。

(4). 提交至版本库
  • git commit filename -m 'message'
(5). 查看某一文件两个版本之间的不同
  • git diff commitID1 commitID2
(6). 查看每次提交的内容与差异
  • git log -p filename
(7). 查看Git的提交历史
  • git log
(8). 可看某文件某一版本内容
  • git show commitIDx filename
(9). 可看某些文件某一版本内容
  • git show commitIDx

TAG:

 

评分:0

我来说两句

Open Toolbar