git学习(1)

2018-04-05  本文已影响0人  王韬_

如何创建git仓库

第一步 创建空目录

midkir 文件名
cd 文件名
pwd
$ mkdir learngit
$ cd learngit
$ pwd
/Users/michael/learngit

第二步 通过git init命令把这个目录变成git可以管理的仓库

$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/

将文件添加到版本库

第一步 创建文件

touch 文件名
touch readme.txt

第二步 把文件添加到仓库

git add readme.txt
git add file1.txt file2.txt file3.txt

第三步 使用 git commit命令把文件提交到仓库

$ git commit -m "wrote a readme file"
[master (root-commit) cb926e7] wrote a readme file
 1 file changed, 2 insertions(+)
 create mode 100644 readme.txt

用git status查看当前仓库状态

$ git status

输出结果

$ git status
# 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:   readme.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

git diff查看修改前后的状态

$ git diff
$ git diff readme.txt 
diff --git a/readme.txt b/readme.txt
index 46d49bf..9247db6 100644
--- a/readme.txt
+++ b/readme.txt
@@ -1,2 +1,2 @@
-Git is a version control system.
+Git is a distributed version control system.
 Git is free software.
上一篇 下一篇

猜你喜欢

热点阅读