- 论坛徽章:
- 0
|
cite from http://www.kernel.org/pub/software/scm/git/docs/gittutorial.html
gittutorial(7) Manual Page
NAME
gittutorial - A tutorial introduction to git (for version 1.5.1 or newer)
SYNOPSIS
git *
DESCRIPTION
This tutorial explains how to import a new project into git, make changes to it, and share changes with other developers.
If you are instead primarily interested in using git to fetch a project, for example, to test the latest version, you may prefer to start with the first two chapters of The Git User's Manual.
First, note that you can get documentation for a command such as git log --graph with:
$ man git-log
or:
$ git help log
With the latter, you can use the manual viewer of your choice; see git-help(1) for more information.
It is a good idea to introduce yourself to git with your name and public email address before doing any operation. The easiest way to do so is:
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com
(译)
git 引导 - 一个引导介绍给git (适合版本 1.5.1 或 更新的)
大纲
git *
描述
这个引导解释了如何去导入一个新的工程到git, 修改它里面的内容,跟其他开发者共享这些改动。
如果你初步不是对使用git去取出一个工程感兴趣,而是,例如, 去测试一个最新的版本,你可以更适合的从git用户手册前两章开始。
首先, 注意你能够获得命令的文档, 例如使用 git log -- 命令如下:
$ man git-log
或者:
$ git help log
后面, 你可以使用手册去查看你的选择:参见 git-help(1) 得到更多的信息。
这是一个很多的主意,在做任何操作之前使用你的名字和公共的email地址去介绍你自己给git。方法如下所示:
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com
Importing a new project
Assume you have a tarball project.tar.gz with your initial work. You can place it under git revision control as follows.
$ tar xzf project.tar.gz
$ cd project
$ git init
Git will reply
Initialized empty Git repository in .git/
You've now initialized the working directory--you may notice a new directory created, named ".git".
Next, tell git to take a snapshot of the contents of all files under the current directory (note the .), with git-add:
$ git add .
This snapshot is now stored in a temporary staging area which git calls the "index". You can permanently store the contents of the index in the repository with git-commit:
$ git commit
This will prompt you for a commit message. You've now stored the first version of your project in git.
(译)
导入一个新的工程
假如你有一个tar压缩工程 project.tar.gz 作为你的初始工作。 你能够放置它到版本控制里,如下所示:
$ tar xzf project.tar.gz
$ cd project
$ git init
Git将返回
在.git/初始化空的Git仓库
你现在已经初始化了以个工作目录--你可以注意到一个新的叫做".git"的目录已经创建完成。
下一步, 告诉git去创建一个当前目录下的所有文件内容的快照(注意 . ), 使用git-add:
$ git add .
这个快照现在存储在一个临时的区域,git称呼这区域为"index"。你能够永久地存储索引的内容在仓库你,使用命令git-commit:
$ git commit
这将有一个提交信息提示你。你现在已经存储了工程里第一个版本到git里了。
Making changes
Modify some files, then add their updated contents to the index:
$ git add file1 file2 file3
You are now ready to commit. You can see what is about to be committed using git-diff with the --cached option:
$ git diff --cached
(Without --cached, git-diff will show you any changes that you've made but not yet added to the index.) You can also get a brief summary of the situation with git-status:
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: file1
# modified: file2
# modified: file3
#
If you need to make any further adjustments, do so now, and then add any newly modified content to the index. Finally, commit your changes with:
$ git commit
This will again prompt you for a message describing the change, and then record a new version of the project.
Alternatively, instead of running git-add beforehand, you can use
$ git commit -a
which will automatically notice any modified (but not new) files, add them to the index, and commit, all in one step.
A note on commit messages: Though not required, it's a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. Tools that turn commits into email, for example, use the first line on the Subject: line and the rest of the commit in the body.
Git tracks content not files
Many revision control systems provide an add command that tells the system to start tracking changes to a new file. Git's add command does something simpler and more powerful: git-add is used both for new and newly modified files, and in both cases it takes a snapshot of the given files and stages that content in the index, ready for inclusion in the next commit.
Viewing project history
At any point you can view the history of your changes using
$ git log
If you also want to see complete diffs at each step, use
$ git log -p
Often the overview of the change is useful to get a feel of each step
$ git log --stat --summary
(译)
做改动
修改一些文件, 然后增加它们更新的内容到索引里:
$ git add file1 file2 file3
你现在准备去提交。你能够看到什么将会被提交,使用git-diff, 带 --cached 选项:
$ git diff --cached
(如果没有 --cached, git-diff 将显示你的已经做过的但还没有增加到索引的任何改变。) 你能够同样的得到主要的总体状态,使用git-status:
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD ..." to unstage)
#
# modified: file1
# modified: file2
# modified: file3
#
如果你需要去做些更远的调整,现在就做,然后增加任何新的已修改的内容到索引。最后,提交你的改动如下:
$ git commit
这将又会提示你描述改动过的信息,然后记录一个新的工程版本。
可选的,而不是提前地运行git-add,你能够使用:
$ git commit -a
这将自动地通知任何已经修改过(但不是新的)文件,增加他们到索引,然后提交,所有集成一步搞定。
提交信息描述:尽管不是必需的,不过这是一个很好的主意在提交信息前,用一个简单短小(小于50字符)行去概述这些改动,紧跟着一个空行和一个更完全的描述。工具集能把提交的转换为email,例如,
使用第一行作为主题:其余的提交作为主体。
Git 跟踪内容,不是文件。
许多修订过的版本系统支持一个增加命令,告诉系统开始跟踪新文件的改动。Git添加的命令能做了更简单和更有力: git-add 被同时用在新的和最近修改的文件,在这些情况下,它做了个给出文件快照和
筹备那些内容到索引里,准备被下一次的提交所包含。
查看工程的历史
在任何的地方,你能够看到你改动过的历史记录,使用:
$ git log
如果你同样想去查看每一步的完全的差异,使用:
$ git log -p
经常,改动的全图是非常很好的给人了解每步变化:
$ git log --stat --summary
Managing branches
A single git repository can maintain multiple branches of development. To create a new branch named "experimental", use
$ git branch experimental
If you now run
$ git branch
you'll get a list of all existing branches:
experimental
* master
The "experimental" branch is the one you just created, and the "master" branch is a default branch that was created for you automatically. The asterisk marks the branch you are currently on; type
$ git checkout experimental
to switch to the experimental branch. Now edit a file, commit the change, and switch back to the master branch:
(edit file)
$ git commit -a
$ git checkout master
Check that the change you made is no longer visible, since it was made on the experimental branch and you're back on the master branch.
(译)
管理分支
一个简单的git仓库能够维护多个开发分支。去创建一个新的分支叫做"experimental", 使用:
$ git branch experimental
如果你现在运行
$ git branch
你将会获得一所有存在的分支列表:
experimental
* master
这个"experimental"分支是你刚刚创建的那个,这里的"master" 分支是一个默认分支,为你自动的创建。这里的*号标识你当前所在的分支; 打印:
$ git checkout experimental
转到experimental分支。现在编辑一个文件,提交改动,和转回到原来的master分支:
(edit file)
$ git commit -a
$ git checkout master
检查你所做的改动不在显示,因为这些改动是处于experimental分支里的,你现在是回到了master分支了。
You can make a different change on the master branch:
(edit file)
$ git commit -a
at this point the two branches have diverged, with different changes made in each. To merge the changes made in experimental into master, run
$ git merge experimental
If the changes don't conflict, you're done. If there are conflicts, markers will be left in the problematic files showing the conflict;
$ git diff
will show this. Once you've edited the files to resolve the conflicts,
$ git commit -a
will commit the result of the merge. Finally,
$ gitk
will show a nice graphical representation of the resulting history.
At this point you could delete the experimental branch with
$ git branch -d experimental
This command ensures that the changes in the experimental branch are already in the current branch.
If you develop on a branch crazy-idea, then regret it, you can always delete the branch with
$ git branch -D crazy-idea
Branches are cheap and easy, so this is a good way to try something out.
(译)
你可以在master分支上做些不同的改动:
(edit file)
$ git commit -a
在这里,这两个分支已经分离的,各自里有不同的改动。要去合并改动从experimental到master里,运行:
$ git merge experimental
如果这些改动不冲突,你就完成了。 如果有冲突,在有疑问的文件里的左边将标记符号,来显示这些冲突:
$ git diff
将显示这样。一旦你已经编辑了文件来解决冲突,
$ git commit -a
将提交合并后的结果。最后,
$ gitk
将显示一个很友好的,这些合并后结果的图形界面。
在这刻,你能够删除experimental分支,使用:
$ git branch -d experimental
这个命令保证这些在experimental里的改动已经合并到当前的分支上。
如果你在一个crazy-idea分支上做开发,然后抱怨它,你能够总是删除分支使用:
$ git branch -D crazy-idea
分支是很轻便的,很容易的,所以这是很好的方法去验证一些东西。
Using git for collaboration
Suppose that Alice has started a new project with a git repository in /home/alice/project, and that Bob, who has a home directory on the same machine, wants to contribute.
Bob begins with:
bob$ git clone /home/alice/project myrepo
This creates a new directory "myrepo" containing a clone of Alice's repository. The clone is on an equal footing with the original project, possessing its own copy of the original project's history.
Bob then makes some changes and commits them:
(edit files)
bob$ git commit -a
(repeat as necessary)
When he's ready, he tells Alice to pull changes from the repository at /home/bob/myrepo. She does this with:
alice$ cd /home/alice/project
alice$ git pull /home/bob/myrepo master
This merges the changes from Bob's "master" branch into Alice's current branch. If Alice has made her own changes in the meantime, then she may need to manually fix any conflicts.
The "pull" command thus performs two operations: it fetches changes from a remote branch, then merges them into the current branch.
Note that in general, Alice would want her local changes committed before initiating this "pull". If Bob's work conflicts with what Alice did since their histories forked, Alice will use her working tree and the index to resolve conflicts, and existing local changes will interfere with the conflict resolution process (git will still perform the fetch but will refuse to merge --- Alice will have to get rid of her local changes in some way and pull again when this happens).
Alice can peek at what Bob did without merging first, using the "fetch" command; this allows Alice to inspect what Bob did, using a special symbol "FETCH_HEAD", in order to determine if he has anything worth pulling, like this:
alice$ git fetch /home/bob/myrepo master
alice$ git log -p HEAD..FETCH_HEAD
This operation is safe even if Alice has uncommitted local changes. The range notation HEAD..FETCH_HEAD" means "show everything that is reachable from the FETCH_HEAD but exclude anything that is reachable from HEAD. Alice already knows everything that leads to her current state (HEAD), and reviewing what Bob has in his state (FETCH_HEAD) that she has not seen with this command
If Alice wants to visualize what Bob did since their histories forked she can issue the following command:
$ gitk HEAD..FETCH_HEAD
This uses the same two-dot range notation we saw earlier with git log.
Alice may want to view what both of them did since they forked. She can use three-dot form instead of the two-dot form:
$ gitk HEAD...FETCH_HEAD
This means "show everything that is reachable from either one, but exclude anything that is reachable from both of them".
Please note that these range notation can be used with both gitk and "git log".
After inspecting what Bob did, if there is nothing urgent, Alice may decide to continue working without pulling from Bob. If Bob's history does have something Alice would immediately need, Alice may choose to stash her work-in-progress first, do a "pull", and then finally unstash her work-in-progress on top of the resulting history.
When you are working in a small closely knit group, it is not unusual to interact with the same repository over and over again. By defining remote repository shorthand, you can make it easier:
alice$ git remote add bob /home/bob/myrepo
With this, Alice can perform the first part of the "pull" operation alone using the git-fetch command without merging them with her own branch, using:
alice$ git fetch bob
Unlike the longhand form, when Alice fetches from Bob using a remote repository shorthand set up with git-remote, what was fetched is stored in a remote tracking branch, in this case bob/master. So after this:
alice$ git log -p master..bob/master
shows a list of all the changes that Bob made since he branched from Alice's master branch.
After examining those changes, Alice could merge the changes into her master branch:
alice$ git merge bob/master
This merge can also be done by pulling from her own remote tracking branch, like this:
alice$ git pull . remotes/bob/master
Note that git pull always merges into the current branch, regardless of what else is given on the command line.
Later, Bob can update his repo with Alice's latest changes using
bob$ git pull
Note that he doesn't need to give the path to Alice's repository; when Bob cloned Alice's repository, git stored the location of her repository in the repository configuration, and that location is used for pulls:
bob$ git config --get remote.origin.url
/home/alice/project
(The complete configuration created by git-clone is visible using git config -l, and the git-config(1) man page explains the meaning of each option.)
Git also keeps a pristine copy of Alice's master branch under the name "origin/master":
bob$ git branch -r
origin/master
If Bob later decides to work from a different host, he can still perform clones and pulls using the ssh protocol:
bob$ git clone alice.org:/home/alice/project myrepo
(译)
使用git来协作开发
假如Alice已经开始一个新的项目,在/home/alice/project下使用git仓库, 和Bob也在同样的机器里有自己的home目录,想共同开发.
Bob开始使用:
bob$ git clone /home/alice/project myrepo
这样创建一个新的目录"myrepo",包含了Alice's仓库的克隆。这个克隆跟原始的工程处于同等的关系,处理它自己的拷贝。
Bob然后做一些改变和提交它们:
(edit files)
bob$ git commit -a
(repeat as necessary)
当他准备好了,他告诉Alice去从/home/bob/myrepo的仓库里取并这个改动。 她就如下做法:
alice$ cd /home/alice/project
alice$ git pull /home/bob/myrepo master
这个合并是从 Bob的"master"分支到 Alice 的当前分支。 如果 Alice 已经同时有了自己的改动。 那么她可能需要手工地处理任何的冲突。
这个取并"pull"命令因此执行两个操作: 它从远方分支取走改动, 然后合并它们到当前的分支。
注意,一般地, Alice将希望她本地变动的提交在加入这个"pull"之前。 如果Bob的工作与Alice的有冲突,因为它们历史的分叉。Alice将使用她的工作树和索引去解决冲突,存在本地的改动将涉及到冲突解决方案的处理。 (git将仍然执行这个取操作,但将拒绝合并 -- Alice将必须使用一些方法处理她本地的改动和继续取并,如果这些发生的话).
Alice 在合并之前能够偷看Bob在干些什么, 使用"fetch"命令;这允许Alice去检查Bob做了些什么, 使用一个特殊的符号"FETCH_HEAD", 为了确定他提交的东西是否值得合并,像如下这样:
alice$ git fetch /home/bob/myrepo master
alice$ git log -p HEAD..FETCH_HEAD
这个操作很安全,甚至Alice还没有提交本地的改动。这个范围HEAD..FETCH_HEAD 意思是显示一切能可获得的从FETCH_HEAD,但除了一切可获得的从HEAD。Alice已经知道能引导她当前状态(HEAD)所有东西, 和检查
还没看到的Bob所在的状态(FETCH_HEAD)。
如果Alice想去图形查看Bob自从她的历史分叉之后做了些什么,她可以发出下面的命令:
$ gitk HEAD..FETCH_HEAD
这使用同样的两个点范围标识,跟使用前面的git log一样。
Alice可能想去查看他们自从他们分叉之后各自做了些什么。她能够使用3个点形式,而不是两个点形式:
$ gitk HEAD...FETCH_HEAD
这意思是"显示一切从我们任何一个里可获得的, 但除了那些可获得的我们共同的"。
请注意这些范围标识能够同时被gitk 和 "git log"使用。
在检查了Bob在做什么之后, 如果没什么紧急事情,Alice可以决定继续工作,而不去取并Bob的。如果Bob的历史有一些是Alice将立即需要的,Alice可以首先选择中断她的所在工作,做一个取并工作,然后最终继续恢复她的工作到她历史版本的最高层。
当你正在工作在一个很小的紧密的组, 通常不去跟同样的仓库交互,依赖定义远方的仓库快链, 你能够使它很容易:
alice$ git remote add bob /home/bob/myrepo
使用这些,alice能够单独执行取并操作的第一部分, 使用git-fetch命令,而不合并它们到她自己的分支上,使用:
alice$ git fetch bob
不像那普通的写法形式, 当Alice使用git-remote设置一个远方仓库的链接来从Bob取得数据,所取得的被存储在远方的跟踪分支中,在这里是bob/master。在这之后:
alice$ git log -p master..bob/master
显示一个Bob所做的自从他从Alice的主分支开叉出来时的所有改动列表。
在验证这些改动后, Alice能合并这些改动到她的主分支里:
alice$ git merge bob/master
这里的合并也能通过从她自己远方的跟踪分支里取并操作来完成,想这样:
alice$ git pull . remotes/bob/master
注意,git取并总是合并到当前分支,不关心命令写的东西。
后来, Bob能更新他的仓库同步Alice的最新改动,使用:
bob$ git pull
注意他不需要去给出Alice的仓库的路径;当Bob克隆Alice的仓库时,git存储她仓库的本地信息到仓库配置里,和这些本地信息被取并时使用到:
bob$ git config --get remote.origin.url
/home/alice/project
(这个完整的配置被git-clone创建,使用git config -l来查看,git-config(1)手册页解释每个操作意思。)
Git 也保留一份原始的Alice主分支的拷贝在"origin/master"里。
bob$ git branch -r
origin/master
如果 Bob 后来决定去从一台不同的主机上工作,他能够仍然执行克隆和取并,使用ssh协议:
bob$ git clone alice.org:/home/alice/project myrepo
Alternatively, git has a native protocol, or can use rsync or http; see git-pull(1) for details.
Git can also be used in a CVS-like mode, with a central repository that various users push changes to; see git-push(1) and gitcvs-migration(7).
Exploring history
Git history is represented as a series of interrelated commits. We have already seen that the git-log command can list those commits. Note that first line of each git log entry also gives a name for the commit:
$ git log
commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
Author: Junio C Hamano
Date: Tue May 16 17:18:22 2006 -0700
merge-base: Clarify the comments on post processing.
We can give this name to git-show to see the details about this commit.
$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
But there are other ways to refer to commits. You can use any initial part of the name that is long enough to uniquely identify the commit:
$ git show c82a22c39c # the first few characters of the name are
# usually enough
$ git show HEAD # the tip of the current branch
$ git show experimental # the tip of the "experimental" branch
Every commit usually has one "parent" commit which points to the previous state of the project:
$ git show HEAD^ # to see the parent of HEAD
$ git show HEAD^^ # to see the grandparent of HEAD
$ git show HEAD~4 # to see the great-great grandparent of HEAD
Note that merge commits may have more than one parent:
$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^)
$ git show HEAD^2 # show the second parent of HEAD
You can also give commits names of your own; after running
$ git tag v2.5 1b2e1d63ff
you can refer to 1b2e1d63ff by the name "v2.5". If you intend to share this name with other people (for example, to identify a release version), you should create a "tag" object, and perhaps sign it; see git-tag(1) for details.
Any git command that needs to know a commit can take any of these names. For example:
$ git diff v2.5 HEAD # compare the current HEAD to v2.5
$ git branch stable v2.5 # start a new branch named "stable" based
# at v2.5
$ git reset --hard HEAD^ # reset your current branch and working
# directory to its state at HEAD^
Be careful with that last command: in addition to losing any changes in the working directory, it will also remove all later commits from this branch. If this branch is the only branch containing those commits, they will be lost. Also, don't use git-reset on a publicly-visible branch that other developers pull from, as it will force needless merges on other developers to clean up the history. If you need to undo changes that you have pushed, use git-revert instead.
(译)
可选地,git有一个本地的协议,或者能够使用rsync或者http;见git-pull(1)获得更详细的信息。
Git 也能够在类CVS模式,使用一个中心的存储,各类的用户去提交改动给它。见git-push(1)和gitcvs-migration(7)。
浏览历史
Git 历史作为一系列相互关联的提交。我们已经看到git-log命令能够列出这些提交。注意每个git log项第一行也为这些提交给出了一个名称:
$ git log
commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
Author: Junio C Hamano
Date: Tue May 16 17:18:22 2006 -0700
merge-base: Clarify the comments on post processing.
我们能够给一个名字给git-show去查阅关于这次提交的内容。
$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7
但是有另一个方法去引用这次提交。你能够使用名字任何首部分,不过这必须足够长的信息去唯一鉴定这次提交:
$ git show c82a22c39c # the first few characters of the name are
# usually enough
$ git show HEAD # the tip of the current branch
$ git show experimental # the tip of the "experimental" branch
每个提交通常有一个"parent"的提交,这指向工程的前一个状态:
$ git show HEAD^ # to see the parent of HEAD
$ git show HEAD^^ # to see the grandparent of HEAD
$ git show HEAD~4 # to see the great-great grandparent of HEAD
注意这合并这些提交可以拥有一个以上的parent:
$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^)
$ git show HEAD^2 # show the second parent of HEAD
你也能够给这些提交命名;运行:
$ git tag v2.5 1b2e1d63ff
你能够通过名字"v2.5"来引用1b2e1d63ff。如果你打算与其他人共享这个名字(例如,去鉴别一个释放版本),你应该创建一个"tag"对象,可能标志它:见git-tag(1)获得更详细信息。
任何git命令需要知道一个提交能够使用任何这些名字。例如:
$ git diff v2.5 HEAD # compare the current HEAD to v2.5
$ git branch stable v2.5 # start a new branch named "stable" based
# at v2.5
$ git reset --hard HEAD^ # reset your current branch and working
# directory to its state at HEAD^
注意最后的命令:除了在工作目录丢掉任何的改动外,它将同样从这个分支删除所有后来的提交。如果这个分支,仅只有这个分支包含这些提交,他们将被丢掉。同样,不要使用git-reset在公共可视的分支,这些分支其他开发者从这里取并的,就如它将强制不必要的合并到其他开发者中,去清除这些历史。如果你需要去撤销你提交的这些改动,使用git-revert代替。
The git-grep command can search for strings in any version of your project, so
$ git grep "hello" v2.5
searches for all occurrences of "hello" in v2.5.
If you leave out the commit name, git-grep will search any of the files it manages in your current directory. So
$ git grep "hello"
is a quick way to search just the files that are tracked by git.
Many git commands also take sets of commits, which can be specified in a number of ways. Here are some examples with git-log:
$ git log v2.5..v2.6 # commits between v2.5 and v2.6
$ git log v2.5.. # commits since v2.5
$ git log --since="2 weeks ago" # commits from the last 2 weeks
$ git log v2.5.. Makefile # commits since v2.5 which modify
# Makefile
You can also give git-log a "range" of commits where the first is not necessarily an ancestor of the second; for example, if the tips of the branches "stable-release" and "master" diverged from a common commit some time ago, then
$ git log stable..experimental
will list commits made in the experimental branch but not in the stable branch, while
$ git log experimental..stable
will show the list of commits made on the stable branch but not the experimental branch.
The git-log command has a weakness: it must present commits in a list. When the history has lines of development that diverged and then merged back together, the order in which git-log presents those commits is meaningless.
Most projects with multiple contributors (such as the Linux kernel, or git itself) have frequent merges, and gitk does a better job of visualizing their history. For example,
$ gitk --since="2 weeks ago" drivers/
allows you to browse any commits from the last 2 weeks of commits that modified files under the "drivers" directory. (Note: you can adjust gitk's fonts by holding down the control key while pressing "-" or "+".)
Finally, most commands that take filenames will optionally allow you to precede any filename by a commit, to specify a particular version of the file:
$ git diff v2.5:Makefile HEAD:Makefile.in
You can also use git-show to see any such file:
$ git show v2.5:Makefile
(译)
git-grep命令能够在你工程的任何版本里查找字符串,这样:
$ git grep "hello" v2.5
在 v2.5里查找所有出现"hello"串。
如果你缺少这提交名, git-grep 将查找文件的任何地方,这些文件在你当前目录中被管理的。
$ git grep "hello"
是一个快速的方法去查找仅仅被git跟踪的文件。
许多git命令也采用提交集形式, 能用许多方法来指定。这里一些例子使用git-log:
$ git log v2.5..v2.6 # commits between v2.5 and v2.6
$ git log v2.5.. # commits since v2.5
$ git log --since="2 weeks ago" # commits from the last 2 weeks
$ git log v2.5.. Makefile # commits since v2.5 which modify
# Makefile
你也能够给出git-log一个范围, 这范围第一个不需要比第二个先;例如,如果分支的提示"stable-release" 和 "master"从一个公共的提交一段时间之前,那么:
$ git log stable..experimental
将列出提交,这些提交来自 experimental分支,而不是 stable 分支, 当
$ git log experimental..stable
将显示提交列表,来自stable 分支, 而不是 experimental 分支。
git-log 命令有些弱点:它必须显示提交到一个列表里。当历史有很多开发行时,被分离,然后被合并回去,那么git-log呈现这些提交的顺序是没意义的。
大部分工程都有多个开发者(例如 Linux 内核,或者 git 自己) 经常要合并, gitk 是很好的浏览他们历史的图形工具。例如:
$ gitk --since="2 weeks ago" drivers/
允许你浏览任何提交,从最近2个星期的提交。这些提交在"drivers"目录修改了文件。 (注意:你能够通过压下control键和同时按"-"或者"+"来调整gitk的字体。)
最后,大部分命令允许你取文件名的前几个字母来提交,去指定一个特殊文件版本:
$ git diff v2.5:Makefile HEAD:Makefile.in
你也能够使用 git-show 去查看任何这样的文件:
$ git show v2.5:Makefile
Next Steps
This tutorial should be enough to perform basic distributed revision control for your projects. However, to fully understand the depth and power of git you need to understand two simple ideas on which it is based:
*
The object database is the rather elegant system used to store the history of your project--files, directories, and commits.
*
The index file is a cache of the state of a directory tree, used to create commits, check out working directories, and hold the various trees involved in a merge.
Part two of this tutorial explains the object database, the index file, and a few other odds and ends that you'll need to make the most of git. You can find it at gittutorial-2(7).
If you don't want to continue with that right away, a few other digressions that may be interesting at this point are:
*
git-format-patch(1), git-am(1): These convert series of git commits into emailed patches, and vice versa, useful for projects such as the Linux kernel which rely heavily on emailed patches.
*
git-bisect(1): When there is a regression in your project, one way to track down the bug is by searching through the history to find the exact commit that's to blame. Git bisect can help you perform a binary search for that commit. It is smart enough to perform a close-to-optimal search even in the case of complex non-linear history with lots of merged branches.
*
Everyday GIT with 20 Commands Or So
*
gitcvs-migration(7): Git for CVS users.
SEE ALSO
gittutorial-2(7), gitcvs-migration(7), gitcore-tutorial(7), gitglossary(7), git-help(1), Everyday git, The Git User's Manual
GIT
Part of the git(1) suite.
Last updated 2009-04-02 06:50:10 UTC
(译)
下一步
这个引导应该足够为你的项目去执行基本分布式版本控制。然而,去完全理解git更深更有力,你需要去理解它基于两个的思想:
*
目标数据库是相当优雅的系统被用来存储你工程(文件,目录,提交)历史。
*
这索引文件是目录树状态的缓冲,被用来创建提交,签出工作目录,保持各种的合并后的树。
这引导的第二部分解释了一个目标数据库,索引文件,和一些其他古怪的东西,和最后你将需要去使用git练习。你能够在gittutorial-2(7)找到它。
如果你不想继续马上使用它,一些其他的东西可能在这里有兴趣:
*
git-format-patch(1), git-am(1): 这些转换一系列的git提交为email包,反之亦然,对工程(例如Linux内核,非常依赖邮件包交流)非常有用。
*
git-bisect(1): 当你的工程需要退回的话,有一个方法通过历史去查找精确的被谴责的提交。Git bitsect能够帮你为这些提交执行一个二分查找。它足够的聪明去执行一个最优化的查找,甚至在复杂的非线性的历史,这些历史带有很多合并的分支。
*
Everyday GIT with 20 Commands Or So
*
gitcvs-migration(7): Git for CVS users.
SEE ALSO
gittutorial-2(7), gitcvs-migration(7), gitcore-tutorial(7), gitglossary(7), git-help(1), Everyday git, The Git User's Manual
GIT
Part of the git(1) suite.
Last updated 2009-04-02 06:50:10 UTC
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/94861/showart_1927898.html |
|