1. 程式人生 > >創建版本倉庫並推送文件

創建版本倉庫並推送文件

恢復 cal 一個 log 信息 roo 版本庫 mit 添加

創建版本倉庫:

[[email protected] ~]# mkdir /home/gitroot    # 這個目錄作為版本倉庫
[[email protected] ~]# cd /home/gitroot/
[[email protected] gitroot]# git init         # 初始化,使得這個目錄變成Git可以管理的倉庫

推送文件到版本倉庫:

[[email protected] gitroot]# cat 1.txt        # 先創建一個文件,然後再把這個文件推送到版本倉庫
1111 2222 3333
[[email protected] gitroot]# git add 1.txt # 先添加到工作區
[[email protected] gitroot]# git commit -m "add new 1.txt" # 提交到版本倉庫,-m 用於添加描述信息(即描述做了哪些修改)
[[email protected] gitroot]# echo "4444" >> 1.txt      # 假設我們更改了文件內容
[[email protected]
/* */ gitroot]# git status # 用於查看是否更改過文件內容,在更改文件之前最後用該命令查看之前是否更改過
[[email protected] gitroot]# git diff # 用於對比更改前後的文件內容,看一下更改了什麽內容 [[email protected] gitroot]# git checkout -- 1.txt # 如果我們不想更改,我們可以恢復到原來的內容 [[email protected] gitroot]# cat 1
.txt 1111 2222 3333

總結:

git init                 # 初始化
git add 1.txt            # 添加到工作區
git commit -m "..." # 提交到版本庫
git status # 查看是否更改了文件
git diff # 對比更改了哪些內容
git checkout -- 1.txt # 恢復到版本庫最新版本的內容

創建版本倉庫並推送文件