第 176 章 Git - Fast Version Control System

过程 176.1. Git

  1. install

    sudo apt-get install git-core
    			
  2. config
    $ git-config --global user.name neo
    $ git-config --global user.email openunix@163.com
    
  3. Initializ
    $ mkdir repository
    $ cd repository/
    
    /repository$ git-init-db
    Initialized empty Git repository in .git/
    			

    to check .gitconfig file

    $ cat ~/.gitconfig
    [user]
            name = chen
            email = openunix@163.com
    			

176.1. Repositories 仓库管理

176.1.1. initial setup

Tell git who you are:

$ git config user.name "FirstName LastName"
$ git config user.email "user@example.com"

If you have many git repositories under your current user, you can set this for all of them

$ git config --global user.name "FirstName LastName"
$ git config --global user.email "user@example.com"

If you want pretty colors, you can setup the following for branch, status, and diff commands:

$ git config --global color.branch "auto"
$ git config --global color.status "auto"
$ git config --global color.diff "auto"

Or, to turn all color options on (with git 1.5.5+), use:

$ git config --global color.ui "auto"
To enable aut-detection for number of threads to use (good for multi-CPU or multi-core computers) for packing repositories, use:

$ git config --global pack.threads "0"
To disable the rename detection limit (which is set "pretty low" according to Linus, "just to not cause problems for people who have less memory in their machines than kernel developers tend to have"), use:

$ git config --global   diff.renamelimit "0"
		

176.1.2. checkout

将 nqp-cc/src/QASTCompilerMAST.nqp 文件 重置到 211ab0b19f25b8c81685a97540f4b1491eb17504 版本

git checkout 211ab0b19f25b8c81685a97540f4b1491eb17504 -- nqp-cc/src/QASTCompilerMAST.nqp
		

176.1.3. Creating and Commiting

$ cd (project-directory)
$ git init
$ (add some files)
$ git add .
$ git commit -m 'Initial commit'
		

176.1.4. Manager remote

remote add

git remote add origin git@localhost:example.git

remote show

git remote show
origin

remote rm

git remote rm origin

添加多个远程仓库

git remote add origin git@localhost:example.git
git remote add another https://gitcafe.com/netkiller/netkiller.gitcafe.com.git
git push origin master
git push another master
		

176.1.5. Status

$ git clone git://10.10.0.5/example.git
Cloning into example...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 5 (delta 1), reused 0 (delta 0)
Receiving objects: 100% (5/5), done.
Resolving deltas: 100% (1/1), done.

neo@neo-OptiPlex-380:~/tmp$ cd example/

neo@neo-OptiPlex-380:~/tmp/example$ git status
# On branch master
nothing to commit (working directory clean)

neo@neo-OptiPlex-380:~/tmp/example$ ls
test1  test2  test3  test4

neo@neo-OptiPlex-380:~/tmp/example$ echo hello > test1

neo@neo-OptiPlex-380:~/tmp/example$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   test1
#
no changes added to commit (use "git add" and/or "git commit -a")

176.1.6. Diff

neo@neo-OptiPlex-380:~/tmp/example$ git diff
diff --git a/test1 b/test1
index e69de29..ce01362 100644
--- a/test1
+++ b/test1
@@ -0,0 +1 @@
+hello

比较 nqp-cc/src/QASTCompilerMAST.nqp 文件 当前版本与 211ab0b19f25b8c81685a97540f4b1491eb17504 版本的区别

git diff 211ab0b19f25b8c81685a97540f4b1491eb17504 -- nqp-cc/src/QASTCompilerMAST.nqp
		

176.1.6.1. --name-only 仅显示文件名

git diff --name-only
			

176.1.7. Cloning

$ git clone git://github.com/git/hello-world.git
$ cd hello-world
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'

176.1.8. Push

$ git clone git://10.10.0.5/example.git
$ cd example
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'

$ git push origin master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 278 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git://10.10.0.5/example.git
   27f8417..b088cc3  master -> master

176.1.9. Pull

$ git pull
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From git://10.10.0.5/example
   27f8417..b088cc3  master     -> origin/master
Updating 27f8417..b088cc3
Fast-forward
 test1 |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
		

176.1.10. fetch

$ git fetch
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 2 (delta 1), reused 0 (delta 0)
Unpacking objects: 100% (2/2), done.
From git://10.10.0.5/example
   b088cc3..7e8c17d  master     -> origin/master
		

176.1.11. Creating a Patch

$ git clone git://github.com/git/hello-world.git
$ cd hello-world
$ (edit files)
$ git add (files)
$ git commit -m 'Explain what I changed'
$ git format-patch origin/master

176.1.12. reset

重置到上一个版本

git log
git reset --hard HEAD^
git log
git push -f
		

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

时间: 2024-09-28 23:16:16

第 176 章 Git - Fast Version Control System的相关文章

Version Control with Git (Udacity)优达学城笔记--L1:What is Version Control

What is Version Control version control: control version Version Cotrol Systems: Git, Subversion, Mercurial Centralized:all users connect to a central, master repository Distributed: each user has the entire repository on their computer git: Distribu

visualstudio-请问如何学习 Team Foundation Version Control (TFVC)

问题描述 请问如何学习 Team Foundation Version Control (TFVC) 如题,新人不知道怎么弄这个东西,但是感觉还是很有必要学习一下,但是官网上面的流程看不太懂...请问有没有写的细致一点的教程吗?或者视频... 解决方案 如果你只是用版本控制,没必要整个TFS都学,只要搞清楚几个基本概念就可以了,如何建集合,如何将现有的项目添加进去,如何签入签出代码,如何合并代码,应用冲突,更进一步的,如何建立分支和合并分支. 这些看msdn很容易学会的. 解决方案二: http

【转】svn:is not under version control and is not part of the commit, yet its child解决办法

来自:http://blog.csdn.net/lufeng20/article/details/7641093    在把写好的代码提交到svn上面时,遇到了一个错误如下: svn: Commit failed (details follow): svn: 'D:\eclipse\StatusInquiry\src\com\cnjmwl\scm\policy' is not under version control and is not part of the commit, yet its

Distributed Access Control System 1.4.27发布 访问控制系统

Distributed Access Control System简称DACS,是一个轻量级单点登录的http://www.aliyun.com/zixun/aggregation/38609.html">访问控制系统.它提供了灵活.模块化的验证方法,强大.透明的规则为基础的Web服务授权检查,CGI程序或几乎任何程序. Distributed Access Control System 1.4.27该版本进行了一些轻微的错误修正版,升级到第三方的支持包,包括Mac OS X10.7.2升

Distributed Access Control System 1.4.26发布 访问控制系统

Distributed Access Control System简称DACS,是一个轻量级单点登录的http://www.aliyun.com/zixun/aggregation/38609.html">访问控制系统.它提供了灵活.模块化的验证方法,强大.透明的规则为基础的Web服务授权检查,CGI程序或几乎任何程序. Distributed Access Control System 1.4.26版本进行一个小小的更新支持第三方软件升级.扩展了HTTP_AUTH,dacsauth(1)

第 128 章 HAProxy - fast and reliable load balancing reverse proxy

128.1. Installing 128.1.1. Ubuntu $ apt-cache search haproxy haproxy - fast and reliable load balancing reverse proxy sudo apt-get install haproxy 启用HAProxy $ sudo vim /etc/default/haproxy # Set ENABLED to 1 if you want the init script to start hapro

项目管理实践【六】自动同步数据库【Using Visual Studio with Source Control System to synchronize database automatically】

在上一篇项目管理实践[五]自动编译和发布网站中,我们讲解了如何使用MSBuild+Robocopy+WebDeployment来自动编译和部署网站,今天,我们来看一下,如何使用MSBuild +SVN来自动同步数据库. 首先,将我们项目中的数据库文件和数据库日志文件放到某个目录下,这里放到StartKitDB目录下,然后在该目录下新建一个名为StartKitDB的文本文件,修改扩展名为proj,实际上,在理论上任何扩展名都可以,然后,使用记事本或其他程序打开文件,将下面的内容复制到其中,保存.

解决“Could not activate Plug-In: Version Control Interface 1.2”

FOR ENGLISH VISITER: Open regedit Remove "HKEY_CURRENT_USER/Software/Allround Automations/PL/SQL Developer/PlugIns/VCS/Init" Or Change it's value to "1″. Have a nice day. 今天同事说他的PL/SQL Developer的VCS插件有问题.怎么弄都搞不定,无论是重新安装PL/SQL Developer 还是 V

项目管理实践【五】自动编译和发布网站【Using Visual Studio with Source Control System to build and publish website automatically】

在上一篇教程项目管理实践[三]每日构建[Daily Build Using CruiseControl.NET and MSBuild] 中,我们讲解了如何使用CCNET+MSBuild来自动编译项目,今天我们讲解一下怎么使用MSBuild+WebDeployment+Robocopy自动编译过和部署ASP.NET网站. 首先安装下面的三个软件: 1.MSBuild.Community.Tasks下载:http://msbuildtasks.tigris.org/files/documents/