1. 程式人生 > >git 建立倉庫,提交檔案

git 建立倉庫,提交檔案

建立版本庫 # 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: 目錄也是這個方法建立並上傳,但是空目錄無法上傳到庫檔案,目錄裡面需要有檔案存在。