一、新建
1.新建一个空文件,使用mkdir rrdai
2.初始化仓库:git init
3.在仓库加入项目:添加index.txt
4.查看状态:git status
Untracked files: //还未纳入管理
(use "git add <file>..." to include in what will be committed)
index.txt
nothing added to commit but untracked files present (use "git add" to track)
5.添加git add ./ 将当前目录全部添加,也可以git add index.txt
6.查看状态:
On branch master
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: index.txt
已将index.txt添加到版本控制器里
7.托付项目:git commit -m "init" //-m表示注释
此时状态:
On branch master
nothing to commit, working tree clean
例如:
git add index.php
把index.php提交到暂存区
git commit -m "新建index.php"
把index.php提交到版本库
二、修改
如果修改了文件,也不要忘记提交到版本库,这个过程和添加文件是一样的
一样是需要两步,让git仓库记录此次改变
修改之后的状态:
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: index.txt
no changes added to commit (use "git add" and/or "git commit -a")
git add index.php
把index.php提交到暂存区
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: index.txt
git commit -m "改了第2行"
把index.php提交到版本库
On branch master
nothing to commit, working tree clean
三、删除
git rm foo.php
rm 'foo.php'
git commit -m "删除foo.php"
[master e4dc37c] 删除foo.php
1 file changed, 0 insertions(+), 0 deletions(-)
delete mode 100644 foo.php
使用git删除不需要add
四、将项目推到远程码云上去
git push 地址 master
//地址代表远程地址,master为主要分支,可以将地址配置简写
git remote add 别名 地址 //将别名赋值给别名
五、将项目下载下来
git pull 地址 master
六、分支
master为主分支,不要轻易更改master,创建新分支,在新分支上修改正确后,再加入master
1.生成新分支:git branch 新分支名字
2.切换分支: git checkout 分支名字
3.合并分支:切换到主分支,然后合并分支 git merge 合并的分支名字
4.删除分支:git branch -d 分支名字
七、远程仓库
1.查看:
查看远程仓库:git remote
查看仓库地址:git remote -v
2.删除远程库别名
命令:git remote remove <远程库别名>
3.添加远程库别名
命令:git remote add <远程库名> <远程库别名>