Permalink
Browse files

Post article git fetch and pull

  • Loading branch information...
1 parent 6b0a3ce commit cbe058571f882ec5c70021e64eca25b68c39f22f @reyesyang committed Feb 26, 2014
@@ -3,7 +3,7 @@ layout: post
title: Ruby 中的 Shallow copy 和 Deep copy
---
-###什么是Shallow copy和Deep copy?
+###什么是 Shallow copy 和 Deep copy?
* Shallow copy
@@ -16,15 +16,15 @@ title: Ruby 中的 Shallow copy 和 Deep copy
> An alternative is a deep copy. Here the data is actually copied over. The result is different from the result a shallow copy gives. The advantage is that A and B do not depend on each other but at the cost of a slower and more expensive copy.
-两者最主要区别就是如何处理引用对象,Shallow copy只复制了对象地址,而Deep copy则复制了被引用对象本身
+两者最主要区别就是如何处理引用对象,Shallow copy 只复制了对象地址,而 Deep copy 则复制了被引用对象本身
-###Ruby中的Shallow copy
+###Ruby 中的 Shallow copy
-Ruby提供的两个复制对象的方法`Object#dup``Object#clone`都是Shallow copy。
+Ruby 提供的两个复制对象的方法 `Object#dup``Object#clone` 都是 Shallow copy。
-###Ruby中的Deep copy
+###Ruby 中的 Deep copy
-Ruby默认没有提供Deep copy,通常有三种方法解决这个问题:
+Ruby 默认没有提供 Deep copy,通常有三种方法解决这个问题:
方法一,使用序列化和反序列化:
@@ -36,7 +36,7 @@ class Object
end
{% endhighlight %}
-不足之处是Marshel不能dump下面这些对象
+不足之处是 Marshel 不能 dump 下面这些对象
1. anonymous Class/Module.
2. objects which related to its system (ex: Dir, File::Stat, IO, File, Socket and so on)
@@ -14,6 +14,39 @@ git checkout new-branchname
git checkout -b new-branchname
```
+**暂存修改过的文件**
+
+```bash
+git add filename
+# 或者
+git add .
+
+git rm filename # 删除工作目录和暂存区中的文件
+
+git rm --cache filename # 删除暂存区中的文件,保留工作目录中的代码
+
+git mv filename new-filename
+```
+
+**提交修改**
+提交暂存区文件
+
+```bash
+git commit -m 'commit comment'
+```
+
+提交所有修改过的文件
+
+```bash
+git commit -am 'commit comment'
+```
+
+```bash
+git commit --amend
+```
+
+**合并分支**
+
**删除分支**
删除合并过的分支
@@ -53,8 +86,30 @@ git branch -d branchname
git push origin :branchname
```
+**HEAD 是那个区域**
+
+**git checkout -- filename, 其中 -- 的作用**
+
+**设置 git clone 时创建的默认分支**
+Git clone additionally creates a remote called ‘origin’ for the repo cloned from, sets up a local branch based on the remote’s active branch (generally master)
+
+```bash
+git symbolic-ref HEAD refs/heads/mybranch
+```
+
+**git reset**
+
+```
+git reset
+git reset --soft
+git reset --hard
+```
+
**参考**
-1. [What's the difference between 'git pull' and 'git fetch'](http://stackoverflow.com/questions/292357/whats-the-difference-between-git-pull-and-git-fetch)
-2. [Visual Git Cheat Sheet ](http://ndpsoftware.com/git-cheatsheet.html)
-3. [Heroku Cheat Sheet](https://na1.salesforce.com/help/doc/en/salesforce_git_developer_cheatsheet.pdf)
+* [A Visual Git Reference](http://marklodato.github.io/visual-git-guide/index-en.html?no-svg)
+* [What's the difference between 'git pull' and 'git fetch'](http://stackoverflow.com/questions/292357/whats-the-difference-between-git-pull-and-git-fetch)
+* [Visual Git Cheat Sheet ](http://ndpsoftware.com/git-cheatsheet.html)
+* [Heroku Cheat Sheet](https://na1.salesforce.com/help/doc/en/salesforce_git_developer_cheatsheet.pdf)
+* [Setting the default git branch in a bare repository](http://feeding.cloud.geek.nz/posts/setting-default-git-branch-in-bare/)
+* [THE DIFFERENCE BETWEEN GIT PULL, GIT FETCH AND GIT CLONE (AND GIT REBASE)](http://blog.mikepearce.net/2010/05/18/the-difference-between-git-pull-git-fetch-and-git-clone-and-git-rebase/)
@@ -0,0 +1,8 @@
+---
+title: Git 入门
+layout: post
+---
+
+**参考**
+
+* [git - the simple guide](http://rogerdudler.github.io/git-guide/)
@@ -0,0 +1,34 @@
+---
+title: git fetch 和 git pull
+layout: post
+---
+
+###git fetch
+获取远程仓库更新到本地仓库
+
+`git fetch` 不加任何参数时,如果当前分支没有设置跟踪分支(tracking branch),则默认获取 origin 远程仓库的更新,否则获取跟踪分支对应远程仓库的更新。
+
+`git fetch --all` 则会获取所有远程仓库的更新。
+
+###git pull
+获取远程仓库更新到本地仓库,并且合并当前所在分支所对应的跟踪分支(tracking branch)代码。等价于下面的两步操作:
+
+```bash
+git fetch
+git merge FETCH_HEAD
+```
+
+另一个接触比较多的命令是 `git pull --rebase`, 则会在合并操作之前先进行一次衍合(rebase)操作。
+假设当前在 master 分支,并且 master 的跟踪分支为 origin/master,则 `git pull --rebase` 等价于下面的三步操作:
+
+```bash
+git pull
+git rebase origin/master
+git merge origin/master
+```
+
+由于进行了衍合(rebase)操作,会改变历史提交记录,所以在公共分支上使用时一定要慎重。
+
+###参考
+1. [git-fetch(1) Manual Page](http://git-scm.com/docs/git-fetch)
+2. [git-pull(1) Manual Page](http://git-scm.com/docs/git-pull)

0 comments on commit cbe0585

Please sign in to comment.