git实际应用

1、拉远程代码到本地仓库

git clone  [url]

2、基本快照

      git status 命令用于查看项目的当前状态。

     接下来我们执行 git add 命令来添加文件:   $ git add README hello.php

     现在我们再执行 git status,就可以看到这两个文件已经加上去了。

$ git status -s
A  README
A  hello.php
$ 



3、

git commit

 

使用 git add 命令将想要快照的内容写入缓存区, 而执行 git commit 将缓存区内容添加到仓库中。

Git 为你的每一个提交都记录你的名字与电子邮箱地址,所以第一步需要配置用户名和邮箱地址。

 

接下来我们写入缓存,并提交对 hello.php 的所有改动。在首个例子中,我们使用 -m 选项以在命令行中提供提交注释。

$ git add hello.php
$ git status -s
A  README
A  hello.php
$ $ git commit -m '第一次版本提交'[master (root-commit) d32cf1f]第一次版本提交2 files changed,4 insertions(+)
 create mode 100644 README
 create mode 100644 hello.php

现在我们已经记录了快照。如果我们再执行 git status:


git reset HEAD

git reset HEAD 命令用于取消已缓存的内容。

 

现在两个文件修改后,都提交到了缓存区,我们现在要取消其中一个的缓存,操作如下:

 

$ git status -s
 M README
 M hello.php
$ git add .
$ git status -s
M  README
M  hello.pp
$ git reset HEAD -- hello.php 
Unstaged changes after reset:
M	hello.php
$ git status -s
M  README
 M hello.php

现在你执行 git commit,只会将 README 文件的改动提交,而 hello.php 是没有的。

$ git commit -m '修改'[master f50cfda]修改1 file changed,1 insertion(+)
$ git status -s
 M hello.php

2016/5/25 22:09

猜你喜欢

转载自yuzhouxiner.iteye.com/blog/2300938