目录
创建Git仓库
两种⽅式:
一、 ⽤ Git 之前还没有项⽬代码
1、指令
#创建仓库
git init projectName
2、演示
$ cd 某个⽂件夹
$ git init your_project #会在当前路径下创建一个名为your_project的仓库
$ cd your_project #该文件夹下面的资源会纳入Git管理
二、 ⽤ Git 之前已经有项⽬代码
1、指令
git init
2、演示
$ cd 项⽬代码所在的⽂件夹
$ git init
也可以创建一个空的仓库,将现有工程直接拖入仓库进行管理。
Git仓库状态
一、准备工作
#创建一个gitDemo文件夹,在gitDemo文件夹下面创建gitResource文件夹
#在gitDemo目录下执行
git init firstProject
cd firstProject
#移动资源到firstProject
mv ../gitResource/index.html index.html
mv ../gitResource/images images
#或者拷贝资源到firstProject
cp ../gitResource/index.html index.html
cp -R ../gitReource2/images/ images
指令
#查看详细状态
git status
#查看精简状态
git status -s
二、添加新文件,查看Git仓库状态
#我们通过拷贝的方式将资源添加到firstProject仓库
LC:firstProject LC$ cp ../gitResource/index.html index.html
LC:firstProject LC$ cp -R ../gitReource2/images/ images
#查看Git状态
LC:firstProject LC$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
images/
index.html
nothing added to commit but untracked files present (use "git add" to track)
LC:firstProject LC$
#精简模式
LC:firstProject LC$ git status --short #或者可以使用 git status -s
?? images/ #??无轨迹,第一次添加(文件第一次添加,未执行add操作)
?? index.html
三、执行add指令,查看Git仓库状态
1、指令
git add fileName
2、演示
#对文件执行 add
LC:firstProject LC$ git add index.html
#查看Git状态
LC:firstProject LC$ git status
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.html
Untracked files:
(use "git add <file>..." to include in what will be committed)
images/
LC:firstProject LC$
#查看精简状态
LC:firstProject LC$ git status -s
A index.html #A代表新添加文件已在暂存区
?? images/
LC:firstProject LC$
3、移除暂存区的指令
#想把文件移除暂存区,可以执行以下指令
git rm --cached index.html
#想把文件夹移除暂存区,可以执行以下指令
git rm -r --cached images #-r代表recursion
四、执行commit指令,查看Git仓库状态
1、指令
git commit -m "your messages"
2、演示
#执行commit指令
LC:firstProject LC$ git commit -m 'add index and images'
[master (root-commit) dee9486] add index and images
2 files changed, 49 insertions(+)
create mode 100644 images/git-logo.png
create mode 100644 index.html
#查看Git状态
LC:firstProject LC$ git status
On branch master
nothing to commit, working tree clean
LC:firstProject LC$
五、修改文件,查看Git仓库状态
#添加 js style 文件夹,并修改index.html文件内容
#查看git状态
LC:firstProject LC$ git status
On branch master
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: js/script.js
new file: styles/style.css
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
LC:firstProject LC$
六、Git仓库状态总结
LC:firstProject LC$ git status
On branch master
#暂存区
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: js/script.js
new file: styles/style.css
#工作区
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: index.html
#纳入管理,但未被追踪
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.html
精简模式说明
??(红色):首次添加,未执行add,工作区
A(绿色):首次添加,执行add,暂存区
M(红色):文件内容有更新,未执行add,工作区
M(绿色):文件内容有更新,执行add,暂存区
行者常至,为者常成!