仓库我原先在github上手动建了一个,直接拿过用吧。
到指定文件夹,输入克隆命令:
$ git clone https://github.com/xinghua521/xinghua.git
查看状态
$ git status
输出:
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
显示是个空的。。。
我在本地文件夹创建了一个txt文本,再次输入状态命令:
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed
test.txt
nothing added to commit but untracked files present (use "git add" to track)
文件名是红红的,并且提示你可以用add命令:
$ git add test.txt
再次查看状态:
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
显示是这样式的哈,说new了一个文件,并且变绿色了,大爱绿灯啊
文件修改后,直接add就好,并不是像svn一样,add一次,然后update
修改后不add,相当于你写完文件 不按Ctrl+s一样
add也只是添加到一个暂存区,并不是直接保存到本地。
接下来提交到本地
$ git commit -m "add a test file"
输出:
[master (root-commit) fdfa530] add a test file
1 file changed, 1 insertion(+)
create mode 100644 test.txt
好了,一个文件发生了改变。
看看改变的日志记录:
$ git log
输出:
commit fdfa5300643a942fc2a55b8e2a4fa6d0e5793913 (HEAD -> master)
Author: xinghua <xinghua5801050@sina.com>
Date: Thu Aug 3 09:53:44 2017 +0800
本地的名称和服务器对应地址不一样哦,不过这歌文件名成可以设置,我就用默认的
$ git remote -v
origin https://github.com/xinghua521/xinghua.git (fetch)
origin https://github.com/xinghua521/xinghua.git (push)
以上操作只是保存到了本地,如果要同步到服务器,还需要发布:
$ git push origin
输出:
Counting objects: 3, done.
Writing objects: 100% (3/3), 262 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/xinghua521/xinghua.git
* [new branch] master -> master
去查看仓库:
哇咔咔,确实是有了哈,只是简单的使用,待哥们继续研究。。。
状态简览
git status
命令的输出十分详细,但其用语有些繁琐。 如果你使用 git status -s
命令或 git status --short
命令,你将得到一种更为紧凑的格式输出。 运行 git status -s
,状态报告输出如下:
$ git status -s
M README
MM Rakefile
A lib/git.rb
M lib/simplegit.rb
?? LICENSE.txt
新添加的未跟踪文件前面有 ??
标记,新添加到暂存区中的文件前面有 A
标记,修改过的文件前面有M
标记。 你可能注意到了 M
有两个可以出现的位置,出现在右边的 M
表示该文件被修改了但是还没放入暂存区,出现在靠左边的 M
表示该文件被修改了并放入了暂存区。 例如,上面的状态报告显示:README
文件在工作区被修改了但是还没有将修改后的文件放入暂存区,lib/simplegit.rb
文件被修改了并将修改后的文件放入了暂存区。 而 Rakefile
在工作区被修改并提交到暂存区后又在工作区中被修改了,所以在暂存区和工作区都有该文件被修改了的记录。