On branch master nothing to commit, working tree clean
更改 server.js
1 2 3 4 5 6 7 8 9 10 11 12
var http = require('http');
http.createServer(function(req, res) { var ret = { succ: true, code:'', message:'', data:''} res.writeHead(200, {'Content-Type': 'text/html'}); res.write(JSON.stringify(ret)); res.end(); }).listen(3000); console.log("HTTP server is listening at port 3000.");
1 2 3 4 5 6 7 8
On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
modified: server.js
no changes added to commit (use "git add" and/or "git commit -a")
提交修改,执行
1 2
git add server.js git commit -m "change the format of result to json"
[[33m290a266[[m[[33m ([[m[[1;36mHEAD -> [[m[[1;32mmaster[[m[[33m)[[m HEAD@{0}: reset: moving to HEAD^ [[33m331b541[[m HEAD@{1}: commit: change the content-type [[33m290a266[[m[[33m ([[m[[1;36mHEAD -> [[m[[1;32mmaster[[m[[33m)[[m HEAD@{2}: commit: change the format of result to json [[33m455d5c9[[m HEAD@{3}: commit (initial): init
可以查看到版本的内部id
回复到 “331b541” 版,执行:
1
git reset --hard 331b541
系统提示:
1
HEAD is now at 331b541 change the content-type
参考文件内容:
1 2 3 4 5 6 7 8 9 10 11 12
var http = require('http');
http.createServer(function(req, res) {
var ret = { succ: true, code:'', message:'', data:''} res.writeHead(200, {'Content-Type': 'application/json'}); res.write(JSON.stringify(ret)); res.end(); }).listen(3000);
console.log("HTTP server is listening at port 3000.");
[[33m331b541[[m[[33m ([[m[[1;36mHEAD -> [[m[[1;32mmaster[[m[[33m)[[m HEAD@{0}: reset: moving to 331b541 [[33m290a266[[m HEAD@{1}: reset: moving to HEAD^ [[33m331b541[[m[[33m ([[m[[1;36mHEAD -> [[m[[1;32mmaster[[m[[33m)[[m HEAD@{2}: commit: change the content-type [[33m290a266[[m HEAD@{3}: commit: change the format of result to json [[33m455d5c9[[m HEAD@{4}: commit (initial): init
理解暂存区
修改 server.js 文件,在文件中增加一行,申明一个 data 对象,并插入到 res 的结果中。 修改后的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
var http = require('http');
http.createServer(function(req, res) {
var ret = { succ: true, code:'', message:'', data:''} var data = { id: 1, title: 'call tom' } ret.data = data
console.log("HTTP server is listening at port 3000.");
执行:
1
git status
系统提示:
1 2 3 4 5 6 7 8
On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)
modified: server.js
no changes added to commit (use "git add" and/or "git commit -a")
使用 add 命令将改变提交到暂存区
1
git add server.js
继续修改 server.js 文件,加入在 data 中添加一个属性:
1 2
var data = { id: 1, title: 'call tom', desc: 'call tom and jack' } `
再次用 git status 命名查看状态,看到如下结果:
1 2 3 4 5 6 7 8 9 10 11
On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage)
modified: server.js
Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory)