From 276a57695b334c7c59006fa5ab5ef12af7118409 Mon Sep 17 00:00:00 2001 From: baiyu Date: Mon, 19 Aug 2013 20:04:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86git=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E8=AF=B4=E6=98=8E=EF=BC=88=E4=B8=AD=E8=8B=B1=E6=96=87?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/git_usage/ch_usage.html.erb | 352 +++++++++++++++----------- app/views/git_usage/en_usage.html.erb | 280 +++++++++++--------- 2 files changed, 355 insertions(+), 277 deletions(-) diff --git a/app/views/git_usage/ch_usage.html.erb b/app/views/git_usage/ch_usage.html.erb index dc5cf23ee..f7b622c44 100644 --- a/app/views/git_usage/ch_usage.html.erb +++ b/app/views/git_usage/ch_usage.html.erb @@ -15,8 +15,8 @@ body table tr td { color: #333; } body table tr td { - color: #333; - font-size: 18px; + color: #000; + font-size: 20px; font-family: "Comic Sans MS", cursive; } body table tr td span { @@ -29,6 +29,26 @@ body p { body table tr td p { color: #333; } +body table tr td span1 { + color: #09C; + font-weight: bold; +} +body table tr td span2 { + font-weight: bold; + color: #09C; +} +body table tr td p span3 { + color: #6C6; +} +body table tr td p span3 { + font-weight: bold; +} +body table tr td p span4 { + color: #F00; +} +body table tr td p span4 { + font-weight: bold; +} @@ -44,33 +64,191 @@ body table tr td p { + + + + +
 
+ + + + + + + + + + +
1、安装
 

Step1:

+

http://code.google.com/p/msysgit下载msysgit, 我们使用的版本是Git-1.7.4-preview20110204.exe

+ + + + +
安装时,选择Checkout as-is, commit as-is,这样Git 就不会修改换行风格了. 其他用缺省设置即可。
+ + + + + + + + + + +
 

Step2:

+

http://code.google.com/p/tortoisegit/下载TortoiseGit,我们使用的版本是Tortoisegit-1.6.5.0-32bit.msi

安装时, 选择TortoisePLink。
+ + + + +
这两个软件安装完成后, 就可以开始使用了。
 
- - - - - - - - - - -

Step1:

打开终端,输入如下命令:

$git config --global user.name “your_name”

-

-

$git config --global user.email “your_email”

- + + +

用户名和email是用来设置自己的用户名和联系方式的(user.name和user.email必须填写,这些将在版本库提交时用到)。

Step3:

+

在目录中右键单击TortoiseGit 再选Create Branch…就可以创建分支了。

+

 

+ + + - + + + + + + + + +
2、配置
 

Tips:

在桌面上点击鼠标右键,选择TortoiseGit的Settings进行设置

Name和Email是用来设置自己的用户名和联系方式的(user.name和user.email必须填写,这些将在版本库提交时用到)。

接着可以定制上下文菜单:

+

我们在Context Menu里勾选的是 CloneSyncCommit

+

在Set Extend Menu Item里勾选的是Import Svn IgnoreShow ReflogBrowse ReferencesStash ApplySubmodule Sync

+ + + + +
 
+ + + + +
3、日常用法
+ + + + +
 
+ + + + + + + +

Step1:

+

创建版本库(两种途径)

+

(a)在文件夹中按右键, 选择Git Create repository here 就可以创建库了,在出现的窗口中, 不勾选选项, 直接按OK。

+

完成上述操作后,可以看到工作区中出现了隐藏目录 .git。这个隐藏的 .git目录就是git版本库(repository)。

+

 

+

(b)从远程服务器上克隆一个已存在的版本库到本地:在目录中单击右键,选择Git Clone... 然后在URL里填入要clone的文件的地址。

 
+ + + + +

Step2:

+

添加文件和文件夹

+

在文件夹中按右键, 选Git Commit -> "master"… ,接着填写Message, 勾选Whole Project 选项, 这样Commit 的时候可以将整个项目的信息全部Commit 上去, 可以实现不需要打Tag 就能Checkout 出每次Commit 的内容.

+

比如:

+

在工作区添加file1.txt,commit以后接着修改file1.txt,再创建一个文件夹dir1, 并且放置一个file2.txt 在dir1 目
+ 录中, 再次commit 时, 就可以将dir1 和file2.txt 一起加入了.

+ + + + +
 
+ + + + +

Step3:

+

创建分支

+

在目录中单击右键,选择TortoiseGit 里的create Branch…就可以创建分支了。

+

勾选Switch to new branch, 就可以跳转到建立好的分支上。

+

比如:

+

添加一个file3.txt 后, commit 修改。接着通过Switch/Checkout….可以切换回master 分支。

+ + + + +
 
+ + + + +

Step4:

+

看分支情况及修改log

+

在目录中单击右键,选择TortoiseGit 里的Show log, 可以看分支情况和修改log。 勾选All Branches 可以看到所有分支的情况.

+

在Message 列中, 绿色 + 的是分支, 红色 + 的是当前工作分支

+ + + + +
 
+ + + + +

Step5:

+

比较版本差异

+

通过按Shift , 可以选中两个版本, 接着再按鼠标右键, 选中Compare revisions, 就可以比较两个revision 了。

+ + + + +
 
+ + + + +

Step6:

+

合并分支

+

首先切换到master 分支, 接着点击鼠标右键选择TortoiseGit 里的Merge,就可以实现将分支合并到主版本。

+ + + + +
 
+ + + + +

Step7:

+

其他操作

+

(a) Stash

+

Git 提供了一个暂存修改的功能, 称为Stash。 在一些程序进行了修改, 但还不
+ 想commit 成revision 时, 就可以将这些修改Stash 起来, 等到后面需要时再将它
+ 们Pop 出来。

+

(b) 忽略文件

+

一些编辑器在修改文件后会产生bak 文件, 一般不希望这些备份文件也加入
+ 库中, 可以选中一个.bak 文件, 然后选择Add to ignore list 中的*.bak, 这样bak 文
+ 件以后就不会被commit 了。

+ + + @@ -81,147 +259,13 @@ body table tr td p {

 

+

Tips:

在碰到不熟悉的命令时,可以通过 git help命令查看git的用户手册,命令如下:

$git help <command>

- +
- - - - - -
 

Step2:

创建版本库(两种途径)

- - - - -

(1)从远程服务器上克隆一个已存在的版本库到本地:

- - - - -

$git clone http://user_name@domain/repo_path.git

- - - - - - - - - - -

其中,domain是服务器的域名(在trustie系统域名222.247.54.100),repo_path.git是版本库在服务器的相对路径(这个地址在trustie系统中会给出)

 

(2)在本地初始化一个版本库,比如将版本库命名为“DEMO”,使用名为/path/to/my/workspace的目录作为个人的工作区根目录,进入该目录后,执行git init创建版本库。

- - - - - - - - - - - - - -

           $cd /path/to/my/workspace

           $mkdir demo

           $cd demo

           $git init 

-

 

-

 

- - - - - - - - - - - - - -

完成上述操作后,可以看到git init命令在工作区创建了隐藏目录 .git。这个隐藏的 .git目录就是git版本库(repository)。

 

Step3:

提交文件到本地仓库:

- - - - -

$git add file1 file2 

- - - - -

files是做了修改的文件,多个文件使用空格隔开。

- - - - -

$git commit –m "commit message" 

- - - - - - - - - - - - - - - - -

通过-m参数设置提交说明为“commit message”,Git强制性的要求在提交过程中需要输入提交说明,可以使用git log命令来查看提交日志。

 

Step4:

将本地分支推送到远程仓库:

上述操作仅仅是在本地建立了一个git版本库,为了协同工作,我们可以将其推送到远程服务器。

- - - - -

$git remote add origin http://user_name@domain/repo_path.git 

- - - - -

远程库别名为origin

- - - - -

$git push origin master 

- - - - -

将本地的master分支推送到origin的master分支

- - - - -
 
- - - - - - - - - - -

Step5:

将远程仓库的分支更新到本地:

当项目小组有成员将其自己的代码推送到服务器,我们可以使用git pull (或者git fetch)获取更新后的代码。

- - - - -

$git pull origin master

- - - - -

将远程库origin的master分支更新到本地的master分支

- + +
diff --git a/app/views/git_usage/en_usage.html.erb b/app/views/git_usage/en_usage.html.erb index 9579ae887..d312a86c0 100644 --- a/app/views/git_usage/en_usage.html.erb +++ b/app/views/git_usage/en_usage.html.erb @@ -31,6 +31,20 @@ body table tr td p { color: #333; font-family: "Comic Sans MS", cursive; } +body table tr td table tr td span1 { + color: #09c; + font-weight: bold; +} +body table tr td span1 { + color: #09c; + font-weight: bold; +} +span3 { + color: #6C6; +} +span4 { + color: #F00; +} @@ -48,190 +62,208 @@ body table tr td p {
 
- + - + - +
  + + + +
 
+ + + + +
1. Installation

Step1:

Enter the following command in the terminal:

Download msysgit from http://code.google.com/p/msysgit, the version we have used is

+

Git-1.7.4-preview20110204.exe.

$git config --global user.name “your_name”

-

-

$git config --global user.email “your_email”

Please tick "Checkout as-is" and "commit as-is" options during installation so git does not modify the line feed style. Other options you can use the default settings.

- - - - +

User name and email are used to set your own user name and contact information( user.name and user.email must be completed because these will be used when submitting the repository).

+
 
+ - - - - +

Tips:

You can read the user manual by enter " git help " command when you are confused, command as follows:

Step2:

+

Download TortoiseGit from http://code.google.com/p/tortoisegit/, the version we have used is

+

Tortoisegit-1.6.5.0-32bit.msi.

+

Please tick "TortoisePLink" option during installation.

+

You can start using Git when you complete the installation.

- - - - -

$git help <command>

- +
+
 
+ - - - - +

Step2:

Create a new repository by two ways, here we go

Step3:

+

You can create a branch with method that right-click the "TortoiseGit" in the directory and check the "Create Branch… " option.

- - - - -

(1) The first way is clone a repository which is already exists from remote Server to local:

- - - - -

$git clone http://user_name@domain/repo_path.git

- - - - +

The "domain" in the command means the server's domain name(the domain name in Trustie system is 222.247.54.100), "repo_path.git" is the relative path(this address will be given in Trustie)

+
 
+ - +

(2) Initialize a repository on the local, we named repository as “DEMO” for example, use the directory "/path/to/my/workspace" as a root of personal workspace.

2. Configuration
- +
- +

Enter the directory, execute the "git init" command to create the repository.

Right-click on the desktop and select the "Settings" in the "TortoiseGit"

+

User name and email are used to set your own user name and contact information( user.name and user.email must be completed because these will be used when submitting the repository).

+

Then you can customize the "Context Menu":

+

Please check the "Clone","Sync" and "Commit" options in the "Context Menu",

+

check the "Import Svn Ignore", "Show Reflog", "Browse References", "Stash Apply" and "Submodule Sync" in the "Set Extend Menu Item".

- - - - - - - - - - - - - -

           $cd /path/to/my/workspace

           $mkdir demo

           $cd demo

           $git init 

-

 

-

 

- - - - - - - - - - - - - -

After completed these operation, you can see "git init " command creates a hidden directory in the workspace and this hidden directory is the git repository.

 

Step3:

Submit the file to the local repository:

- - - - -

$git add file1 file2 

- - - - -

"file1" is the file which is already modified, multiple files separated by spaces.

- - - - -

$git commit –m "commit message" 

- - - - +

commit message”is a submission instructions which is a mandatory requirement in the Git, you can use "git log" to list the commit log.

+
 
+ - - - - - - - +

Step4:

Push the local branches to the remote repository:

The operation we mentioned above is only to establish a local git repository, we can push it to the remote server in order to work together in the future.

3. Simple usage
- +
- +

$git remote add origin http://user_name@domain/repo_path.git 

Step1:

+

Create a new repository by two ways, here we go

+

(a) You can create a repository by right-click in the folder and select "Git Create repository here". Uncheck any options in the new window, instead of it please click "OK".

+

After completed these operation, you can see there is a hidden directory ( .git ) in the workspace and this hidden directory is the git repository.

+

(b) Clone a exist version from the remote server to local: right-click in the folder and select " Git Clone.." and fill in the URL where you had clone from.

- +
- +

In Git, we call remote repository as origin

 
- +
- +

$git push origin master 

Step2:

+

Add the new file and folder

+

Right-click in the folder and select Git Commit -> "master"… , then fill in the "Message" and check the " Whole Project " option so that the whole information of the project can commit.

+

For example:

+

Create a new file in the workspace named "file1.txt", commit it, and then creat a new folder in the workspace named "dir1", after that create a new file again, but this file is in the folder dir1, named "file2.txt". After that select "Git Commit", then file1 and dir1 can be joined together.

- +
- +

Push the local master branch to the origin master branch .

 
- +
- +
 

Step3:

+

Create a new Branch

+

You can create a new branch by right-click in the folder and select TortoiseGit -> " create Branch… ".

+

You will switch to the new branch when you check "Switch to new branch" option.

+

For example:

+

Create a new file in the workspace named "file3.txt", commit it. And you can switch to the "master" by select the "Switch/Checkout..." in the "TortoiseGit".

- +
- - - - - - - +

Step5:

Get the latest branch from the remote repository:

When your team members push the code to the server, we can use "git pull " (or "git fetch") to obtain the modified code.。

 
- +
- +

$git pull origin master

Step4:

+

View and modify the log

+

You can view the situation of the branch by right-click in the folder and select TortoiseGit -> " Show log". Even you can also modify the log in it. And you can view all the branch's situation by check the " All Branches " option.

+

In the "Message" colume, branch is + green + and the current branch is red + .

- +
- +

Pull the remote master branch to the local master branch.

 
- +
- + +
 

Step5:

+

Compare the version

+

You can select two version in the same time by press "shift", and you can compare the different between two version by right-click the " Compare revisions ".

+ - + + +
--By Trustie Team 
+ + + + +

Step6:

+

Merge the branch

+

First, you should switch to the "master", then righr-click on it and select TortoiseGit -> "Merge" so that the branch can merge into the main version.

+ + + + +
 
+ + + + +

Step7:

+

Other operations

+

(a) Stash

+

Git provides a function named Stash to temporarily store the revised programs. When you revise some programs but still do not want to commit them, you can stash these revised programs and pop them if you need them then.

+

(b) Ignore Files

+

The editor will generate some .bak files after editing. If you do not want to add these .bak files to the repository you can select the ".bak" file and check the "*.bak" in the " Add to ignore list". Then the .bak files will not be commited.
+

+


+

+ + + + +
 
+ + + + +

Tips:

+

You can read the user manual by enter " git help " command when you are confused, command as follows:

+ + + + +
$git help <command>
+ + + + +
 
+ + + + + +
 
+ + +
—— By Trustie Team

 

@@ -239,7 +271,9 @@ body table tr td p {

 

 

 

- - +

 

+

 

+

 

+