git 创建仓库,提交文件

来源:互联网 发布:中国吸引外资国别数据 编辑:程序博客网 时间:2024/05/16 05:18
创建版本库
# mkdir /home/gitroot # 创建存储版本的仓库
# cd /home/gitroot/
# git init # 初始化命令,使目录变成 git 可以管理的仓库
Initialized empty Git repository in /home/gitroot/.git/
提示初始化了一个空的目录 /home/gitroot/.git,一个隐藏的 git 目录


提交文件到仓库
# vim 1.txt # 在 /home/gitroot 目录下 创建1.txt,写入多行
# git add 1.txt # 把 1.txt 增加到仓库
# git commit -m "net 1.txt" # 增加之后使用 commit 命令把文件提交到 git 仓库里面。commit: Record changes to the repository(仓库),双引号内容自定义。
NOTE: 文件必须在 /home/gitroot 自定义的仓库中,否则无法 add。

修改文件后提交
# echo "111" > 1.txt
# git status # 获取当前仓库的状态,随时可以获取,最后一次更改后,无论多久都可以。每次在修改文件之前,一定先看一下 status
# On branch master# 在 master 分支上面
# Changed but not updated:#更改,但没有更新,接下来可以提交,也可以恢复之前的状态
# (use "git add <file>..." to update what will be committed)# git add file 更新
# (use "git checkout -- <file>..." to discard changes in working directory)# 恢复上一次版本库文件
#
# modified: 1.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

# git diff # 查看版本更改的状态
diff --git a/1.txt b/1.txt# 两个版本,a 仓库里的文件,b 本地文件
index ec6122e..7170464 100644
--- a/1.txt
+++ b/1.txt
@@ -7,3 +7,4 @@ af
sdf
adga
+111# 提示这里有更改

# git add 1.txt # 提交文件
# git commit -m "add one line 111"# 更新到仓库
一定要 git commit -m "description" ,否则使用 git diff,或者使用 git status 依然可以查看到有更新或者更改的提示。


NOTE: 目录也是这个方法创建并上传,但是空目录无法上传到库文件,目录里面需要有文件存在。