1. 程式人生 > >1 安裝及添加文件到倉庫

1 安裝及添加文件到倉庫

符號鏈接 col repos gre -exec 提交 bare bsp 分布

1.安裝Git(Linux)

Git是分布式版本管理系統。系統為ubuntu16.03,bash中輸入git看是否已經安裝:

l@ubuntu:~$ git
程序“git”尚未安裝。 您可以使用以下命令安裝:
sudo apt install git

安裝後:

l@ubuntu:~$ git
usage: git [--version] [--help] [-C <path>] [-c name=value]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [
-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>] 這些是各種場合常見的 Git 命令: 開始一個工作區(參見:git help tutorial) clone 克隆一個倉庫到一個新目錄 init 創建一個空的 Git 倉庫或重新初始化一個已存在的倉庫 在當前變更上工作(參見:git help everyday) add 添加文件內容至索引
mv 移動或重命名一個文件、目錄或符號鏈接 reset 重置當前 HEAD 到指定狀態 rm 從工作區和索引中刪除文件 檢查歷史和狀態(參見:git help revisions) bisect 通過二分查找定位引入 bug 的提交 grep 輸出和模式匹配的行 log 顯示提交日誌 show 顯示各種類型的對象 status 顯示工作區狀態 擴展、標記和調校您的歷史記錄 branch 列出、創建或刪除分支 checkout 切換分支或恢復工作區文件 commit 記錄變更到倉庫
diff 顯示提交之間、提交和工作區之間等的差異 merge 合並兩個或更多開發歷史 rebase 本地提交轉移至更新後的上遊分支中 tag 創建、列出、刪除或校驗一個 GPG 簽名的標簽對象 協同(參見:git help workflows) fetch 從另外一個倉庫下載對象和引用 pull 獲取並整合另外的倉庫或一個本地分支 push 更新遠程引用和相關的對象 命令 git help -agit help -g 顯示可用的子命令和一些概念幫助。 查看 git help <命令>git help <概念> 以獲取給定子命令或概念的 幫助。

最後:

l@ubuntu:~/learngit/practice$ git config --global user.name ‘name
l@ubuntu:~/learngit/practice$ git config --global user.email ‘youremail

2.創建版本庫

版本庫/倉庫/repository

先創建一個空目錄:

l@ubuntu:~$ mkdir learngit
l@ubuntu:~$ cd learngit
l@ubuntu:~/learngit$ pwd
/home/l/learngit

然後通過git init命令把這個目錄變成Git可管理的倉庫:

l@ubuntu:~/learngit$ git init
初始化空的 Git 倉庫於 /home/l/learngit/.git/

當前目錄多了個 .git目錄,它是Git來跟蹤管理版本庫的,不要動它。

把文件添加到版本庫:

l@ubuntu:~/learngit$ cd practice/
l@ubuntu:~/learngit/practice$ ls
l@ubuntu:~/learngit/practice$ vim readme.txt

在learngit目錄下或子目錄建一個文件寫入

Git is a version control system.
Git is free software.

把文件放到Git倉庫要兩步:

$ git add readme.txt                             #一用git add告訴Git把文件添加到倉庫

$ git commit -m ‘wrote a readme file‘ #二用git commit告訴Git把文件提交到倉庫,-m後面輸入的是本次提交的說明,寫入有意義的內容,方便查找改                               #動記錄,下面顯示一個文件被改動,插入了兩行內容。
[master (根提交) a6d6684] wrote a readme file
1 file changed, 2 insertions(+)
create mode 100644 practice/readme.txt

Git可以用add多次添加用commit一次提交很多文件。

總結:

1 用git init初始化一個倉庫

2添加文件到Git倉庫:

  a 使用git add,註意可反復多次使用,添加多個文件

  b 使用git commit,完成

1 安裝及添加文件到倉庫