首页 > PHP资讯 > 工具库 > git的安装和git基本操作

git的安装和git基本操作

工具库

git的初始化和基本操作

第一使用:git下载后,直接点击下一步下一步安装,然后第一步自报家门

$ git config --global user.name "用户名"
$ git config --global user.email "邮箱"
c:/用户[documents users]/电脑用户名/.gitconfig

W@thinksite MINGW64 ~

$ git config --global user.name "thinksitelaowang01"

 

W@thinksite MINGW64 ~

$ git config --global user.email "thinksite@126.com"

 

第二步创建本地仓库
1、创建空文件夹 d:/thinksitegit
2、$ git init 在本文件夹中创建仓库 ~代表根目录
使用cd命令进入本目录,pwd查看当前本目录

W@thinksite MINGW64 ~

$ cd d:

 

W@thinksite MINGW64 /d

$ cd thinksitegit

 

W@thinksite MINGW64 /d/thinksitegit

$ pwd

/d/thinksitegit

 

W@thinksite MINGW64 /d/thinksitegit

$ git init

Initialized empty Git repository in D:/thinksitegit/.git/

 

4.1文件的添加和提交

查看git状态: $ git status

  1. 1、在目录下创建一个文件hello.txt,里面输入一行welcome to git
  2. 2、$ git add 文件名 将文件添加/git add 文件名1 文件名2 ..../git add .
  3. 3、$ git commit -m "说明文字" 将文件提交

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

 

No commits yet

 

nothing to commit (create/copy files and use "git add" to track)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

 

No commits yet

 

Untracked files:

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

 

        hello.txt

 

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

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

 

No commits yet

 

Changes to be committed:

  (use "git rm --cached <file>..." to unstage)

 

        new file:   hello.txt

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "add file hello.txt"

[master (root-commit) a630654] add file hello.txt

 1 file changed, 1 insertion(+)

 create mode 100644 hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

   

   W@thinksite MINGW64 /d/thinksitegit (master)

添加和提交多个文件步骤:

 

$ git status

On branch master

Untracked files:

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

 

        hello1.txt

        hello2.txt

 

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

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello1.txt hello2.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes to be committed:

  (use "git reset HEAD <file>..." to unstage)

 

        new file:   hello1.txt

        new file:   hello2.txt

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "add more hello1.txt hello2.txt"

[master 2afbe02] add more hello1.txt hello2.txt

 2 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 hello1.txt

 create mode 100644 hello2.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

 

4.2文件的修改和提交

1、先修改文件

2、使用git status进行查看状态

3、查看修改内容git diff

4git add 文件名  添加

5git commit -m “说明文字”

W@thinksite MINGW64 /d/thinksitegit (master)

$ 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:   hello.txt

 

no changes added to commit (use "git add" and/or "git commit -a")

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git diff

diff --git a/hello.txt b/hello.txt

index 7618940..007c377 100644

--- a/hello.txt

+++ b/hello.txt

@@ -1 +1,2 @@

-welcome to git

\ No newline at end of file

+welcome to git

+this is modify hello.txt

\ No newline at end of file

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git add hello.txt

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

Changes to be committed:

  (use "git reset HEAD <file>..." to unstage)

 

        modified:   hello.txt

 

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git commit -m "modify hello.txt"

[master c181616] modify hello.txt

 1 file changed, 2 insertions(+), 1 deletion(-)

 

W@thinksite MINGW64 /d/thinksitegit (master)

$ git status

On branch master

nothing to commit, working tree clean

本文由欣才IT学院整理发布,未经许可,禁止转载。