From 48532993de55beb1315104de4dd8d21cf34a3f59 Mon Sep 17 00:00:00 2001
From: Soon Van So let's start by creating a new branch and switching to it. You can do
that by running git branch (branchname)
.
+
$ git branch testing
@@ -306,7 +307,7 @@ class HiWorld
revert to what it was before I switched branches. Here I can change
something different (in this case the printed output) and at the same
time rename the file from
hello.rb
to ruby.rb
.
-
+
$ git checkout master @@ -372,7 +373,7 @@ HiWorld.hello of code is edited in different branches there is no way for a computer to figure it out, so it's up to us. Let's see another example of changing the same line in two branches. -+
$ git branch @@ -504,6 +505,7 @@ M READMEgit log
when you are in that branch. For example, if we rungit log
in the Hello World project that we have been working on in this section, we'll see all the commit messages that we've done. +$ git log diff --git a/creating/index.html b/creating/index.html index a6f14b4..7eb90ca 100644 --- a/creating/index.html +++ b/creating/index.html @@ -17,6 +17,7 @@ layout: reference public Git repository, as you would do if you wanted a copy or wanted to work with someone on a project. We will cover both of these here. + @@ -31,9 +32,10 @@ layout: reference- To create a repository from an existing directory of files, you can +To create a repository from an existing directory of files, you can simply run
git init
in that directory. For example, let's say we have a directory with a few files in it, like this: +$ cd konichiwa @@ -41,27 +43,30 @@ layout: reference README hello.rb- This is a project where we are writing examples of the "Hello World" +This is a project where we are writing examples of the "Hello World" program in every language. So far, we just have Ruby, but hey, it's a start. To start version controlling this with Git, we can simply run
git init
. +$ git init Initialized empty Git repository in /opt/konichiwa/.git/- Now you can see that there is a.git
subdirectory in your +Now you can see that there is a
.git
subdirectory in your project. This is your Git repository where all the data of your project snapshots are stored. +$ ls -a . .. .git README hello.rb- Congratulations, you now have a skeleton Git repository and can start +Congratulations, you now have a skeleton Git repository and can start snapshotting your project. +
In a nutshell, you use
git init
to make an diff --git a/inspect/index.html b/inspect/index.html index f3ac1a5..dcf86f3 100644 --- a/inspect/index.html +++ b/inspect/index.html @@ -417,7 +417,8 @@ index bb86f00..192151c 100644That's what we're looking for, but we don't want to have to figure out what commit the two branches diverged from every time. Luckily, Git has a - shortcut for this. If you run
diff --git a/remotes/index.html b/remotes/index.html index 3c91f61..e9d75ff 100644 --- a/remotes/index.html +++ b/remotes/index.html @@ -315,6 +315,7 @@ From github.com:schacon/hwgit diff master...erlang
(with three dots in between the branch names), Git will automatically figure out + shortcut for this. If you rungit diff master...erlang
(with + three dots in between the branch names), Git will automatically figure out what the common commit (otherwise known as the "merge base") of the two commit is and do the diff off of that.If you have more than one remote repository, you can either fetch from specific ones by running
git fetch [alias]
or you can tell Git to synchronize with all of your remotes by runninggit fetch --all
. +In a nutshell you run
git fetch [alias]
to synchronize your @@ -358,7 +359,7 @@ To git@github.com:schacon/hw.git what I have committed and all of its history.What if I have a topic branch like the 'erlang' branch we created earlier - and I just want to share that? You can just push that branch instead. + and I just want to share that? You can just push that branch instead.
$ git push github erlang @@ -403,6 +404,7 @@ fast-forwards' section of 'git push --help' for details.You can fix this by running
git fetch github; git merge github/master
and then pushing again. +In a nutshell you run
git push [alias] [branch]
to update a diff --git a/zh/branching/index.html b/zh/branching/index.html index c5d8295..c706790 100644 --- a/zh/branching/index.html +++ b/zh/branching/index.html @@ -79,6 +79,7 @@ $ git branch我们动手创建一个分支,并切换过去。执行
git branch (branchname)
即可。 +$ git branch testing @@ -334,7 +335,7 @@ HiWorld.hello那么,Git 合并很有魔力,我们再也不用处理合并冲突了,对吗?不太确切。 不同分支中修改了相同区块的代码,电脑自己猜不透神马的情况下,冲突就摆在我们面前了。 我们看看两个分支中改了同一行代码的例子。 -
+
$ git branch diff --git a/zh/creating/index.html b/zh/creating/index.html index ac69689..2cf32d6 100644 --- a/zh/creating/index.html +++ b/zh/creating/index.html @@ -27,7 +27,8 @@ layout: zh_reference- 在目录中执行git init
,就可以创建一个 Git 仓库了。比如,我们恰好有个目录,里头有些许文件,如下: +在目录中执行
git init
,就可以创建一个 Git 仓库了。比如,我们恰好有个目录,里头有些许文件,如下: +$ cd konichiwa $ ls @@ -54,7 +55,8 @@ Initialized empty Git repository in /opt/konichiwa/.git/ . .. .git README hello.rb- 恭喜,现在你就有了一个 Git 仓库的架子,可以开始快照你的项目了。 +恭喜,现在你就有了一个 Git 仓库的架子,可以开始快照你的项目了。 +
简而言之,用
git init
来在目录中创建新的 Git 仓库。 diff --git a/zh/inspect/index.html b/zh/inspect/index.html index 9851a0d..0c5ae53 100644 --- a/zh/inspect/index.html +++ b/zh/inspect/index.html @@ -437,7 +437,7 @@ index bb86f00..192151c 100644 2 files changed, 9 insertions(+), 0 deletions(-) -当然,我会推荐简单点的那个。> +
当然,我会推荐简单点的那个。