美文网首页
1.git初始化 init repository(init ad

1.git初始化 init repository(init ad

作者: 40c5c9e8ed6b | 来源:发表于2018-02-10 09:18 被阅读0次

创建版本库 (init)

新建个人文件夹,并到指定文件夹下 cd xx

为了更好地使用 git, 我们同时也记录每一个施加修改的人. 这样人和修改能够对应上. 所以我们在 git 中添加用户名 user.name 和 用户 email user.email:

$ git config --global user.name "Joyson chen"
$ git config --global user.email "joysonchen@qq.com"

然后我们就能在这个文件夹中建立 git 的管理文件了:

$ git init

因为这个文件夹中还没有任何的文件, 它返回出来一句话告诉我们已经建立了一个空的 git 管理库.

添加文件管理 (add)

通常我们执行 $ ls 就能看到文件夹中的所有文件, 不过 git 创建的管理库文件 .git 是被隐藏起来的. 所以我们要执行这一句才能看到被隐藏的文件:

$ ls -a
# . ..  .git

建立一个新的 1.txt 文件:

$ touch 1.txt

现在我们能用 status 来查看版本库的状态:

$ git status

# 输出
On branch master    # 在 master 分支

Initial commit

Untracked files:    
  (use "git add <file>..." to include in what will be committed)

    1.txt        # 1.txt 文件没有被加入版本库 (unstaged)

nothing added to commit but untracked files present (use "git add" to track)

现在 1.txt 并没有被放入版本库中 (unstaged), 所以我们要使用 add 把它添加进版本库 (staged):

$ git add 1.txt

# 再次查看状态 status
$ git status

# 输出
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   1.txt    # 版本库已识别 1.txt (staged)

如果想一次性添加文件夹中所有未被添加的文件, 可以使用这个:

$ git add .

提交改变 (commit)
我们已经添加好了 1.txt 文件, 最后一步就是提交这次的改变, 并在 -m 自定义这次改变的信息:

$ git commit -m "create 1.txt"

# 输出
[master (root-commit) 6bd231e] create 1.txt
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 1.txt

流程图
整个上述过程可以被这张 git 官网上的流程图直观地表现:


2-1-1.png

相关文章

网友评论

      本文标题:1.git初始化 init repository(init ad

      本文链接:https://www.haomeiwen.com/subject/enrctftx.html