git 入门教程之版本管理
版本管理
背景
在上一節中我們已經成功創建版本庫并且已經添加test.txt等文件,這一節我們繼續講解如何進行版本控制.
首先我們先查看test.txt 文件有什么內容吧!
# 查看文件內容 $ cat test.txt git test git init git diff $ 復制代碼接下來模擬正常工作,接著輸入一下內容:
# 追加新內容到 test.txt 文件 echo "understand how git control version" >> test.txt# 查看當前文件內容 $ cat test.txt git test git init git diff understand how git control version $ 復制代碼緊接著運行 git status 看一下輸出結果:
# 查看文件狀態 $ git status On branch master Changes to be committed:(use "git reset HEAD <file>..." to unstage)modified: test.txtChanges 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: test.txt$ 復制代碼從上述 git status 命令輸出的結果可以看出,test.txt 已經被修改但還沒提交,但是具體發生了什么變化卻沒能告訴我們,如果能夠告訴我們具體修改細節那就好了!
運行**git diff**命令可以實現上述需求
$ git diff diff --git a/test.txt b/test.txt index 729112f..989ce33 100644 --- a/test.txt +++ b/test.txt @@ -1,3 +1,4 @@git testgit initgit diff +understand how git control version $ 復制代碼git diff 命令即查看差異(difference),從輸出結果可以看出我們在最后一行新增了understand how git control version 文字.
通過git status 知道文件發生了改動,git diff 讓我們看到了改動的細節,現在我們提交到版本庫就放心多了,還記得上節課如何添加版本庫的命令嗎?
分兩步操作: git add <file> 和 git commit -m <remark>
第一步: git add <file>
$ git add test.txt $ 復制代碼等一下,在執行 git commit 命令之前,我們再運行 git status 命令查看一下當前倉庫狀態:
$ git status On branch master Changes to be committed:(use "git reset HEAD <file>..." to unstage)modified: test.txt$ 復制代碼此時 git status 命令告訴我們 test.txt 文件已被修改等待提交,好了,那么接著第二步的commit吧!
第二步: git commit -m <remark>
# 提交到版本庫并添加備注 $ git commit -m "add understand how git control version" [master 36f234a] add understand how git control version1 file changed, 2 insertions(+) $ 復制代碼提交后,我們此時再次運行git status 命令查看當前倉庫狀態:
$ git status On branch master nothing to commit, working tree clean $ 復制代碼輸出結果顯示沒有需要提價的改動,工作目錄是干凈的.
小結
- 查看工作區狀態 git status
- 比較修改差異 git diff
轉載于:https://juejin.im/post/5c8efde96fb9a070f12572da
總結
以上是生活随笔為你收集整理的git 入门教程之版本管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 02c语言指针基础
- 下一篇: 人类资产数字化是大势所趋