为何每次 git commit 之前都需要 add 一次才能 commit ?

git 暂存区的意义是什么?
1.git 的 add ,是一个容易引起疑问的命令。在 subversion 中的 svn add 动作是将某个文件加入版本控制,而 git add的意义完全不同。

同时, git diff --cached 是比较 stage 的文件的差异的,也是一个不直观的命令。

github 2008年的blog中,也提到,容易引起混淆:
https://github.com/blog/196-gittogether-2008
http://learn.github.com/p/normal.html

things like making use of the term ‘stage’ for things that happen in the index (such as using ‘git diff —staged’ instead of ‘git diff —cached’) is being worked on. I’m excited that staging files may soon be done via ‘git stage’ rather-than/in-addition-to ‘git add’. This is nice for new users who often have a hard time seeing why you have to keep ‘git add’ing to stage your changes.

Read More

git常见问题及解决方法

远程已经删除的分支,但是本地还存在此分支,怎么把本地分支和远程仓库同步?

在你经常使用的命令当中有一个git branch –a用来查看所有的分支,包括本地和远程的。但是时间长了你会发现有些分支在远程其实早就被删除了,但是在你本地依然可以看见这些被删除的分支。

先调用git remote show origin,该命令能够获取远端分支信息,你可以看到和本地和远端不同步的地方

过时的就是和本地不同步的分支,本地已过时的表示你需要移除这个分支了。

这个时候你需要调用 git remote prune origin,同步远程的分支到本地,这样远程已经被删除的分支,本地就不会再看见了。

Read More

sprintf() 使用手记

用法: string sprintf(string format, mixed [args]…);
传回值:字串
函式种类:资料处理
内容说明:本函式用来将字串格式化。参数 format 是转换的格式,以百分比符号 % 开始到转换字符为止。

在转换的格式间依序包括了:

  1. 处理字符方向。-负号时表时从后向前处理。
  2. 填空字元。 0 的话表示空格填 0;空格是内定值,表示空格就放着。
  3. 字符宽度。注意:这里是指字符的最小总宽度。
  4. 精确度。指在小数点后的浮点数位数。

Read More