1. 程式人生 > 其它 >Java設計模式-策略模式

Java設計模式-策略模式

git基礎

獲取 Git 倉庫

通常有兩種獲取 Git 專案倉庫的方式:

  1. 將尚未進行版本控制的本地目錄轉換為 Git 倉庫。
  2. 從其它伺服器 克隆 一個已存在的 Git 倉庫。

在已存在目錄中初始化倉庫

  1. 進入進入該專案目錄中
  cd my_project
  1. 初始化
  git init

注:該命令將建立一個名為 .git 的子目錄,這個子目錄含有你初始化的 Git 倉庫中所有的必須檔案,這些檔案是 Git 倉庫的骨幹。 但是,在這個時候,我們僅僅是做了一個初始化的操作,你的專案裡的檔案還沒有被跟蹤

  1. 所需的檔案來進行追蹤
  git add '指定檔案'
  // or
  git add . // 目錄下所有檔案
  git commit -m 'commit的內容'

克隆現有的倉庫

  git clone '倉庫地址'

注:克隆後的庫名和連結庫名一致

  git clone '倉庫地址' mylibgit

注:這會執行與上一條命令相同的操作,但目標目錄名變為了 mylibgit

記錄每次更新到倉庫

  1. 檢查當前檔案狀態
 git status
  1. 檢視已暫存和未暫存的修改
 git diff
  1. stash
  // 能夠將所有未提交的修改(工作區和暫存區)儲存至堆疊中,用於後續恢復當前工作目錄
  git stash

  // 檢視當前stash中的內容
  git stash list

  // 存在堆疊中內容應用到當前目錄 (棧: 先進後出), 移除的同時從堆疊中刪除
  git stash pop

  // 將堆疊中的內容應用到當前目錄 該命令不會將內容從堆疊中刪除
  git stash apply

  // 從堆疊中移除某個指定的stash(如stash@{1})
  git stash drop  名稱

  // 清除堆疊中的所有 內容
  git stash clear

  // 檢視堆疊中最新儲存的stash和當前目錄的差異
  git stash show

  // 從最新的stash建立分支
  git stash branch

  1. 忽略檔案

.git目錄同級建立.gitignore

.idea
*.iml
npm-debug.log
node_modules
.DS_Store
.tags
.tags1
__tmp
dist
dist-private
resource
static-cache
.vscode
.history
*.zip

檔案 .gitignore 的格式規範如下

  • 所有空行或者以 # 開頭的行都會被 Git 忽略。
  • 可以使用標準的 glob 模式匹配,它會遞迴地應用在整個工作區中。
  • 匹配模式可以以(/)開頭防止遞迴。
  • 匹配模式可以以(/)結尾指定目錄。
  • 要忽略指定模式以外的檔案或目錄,可以在模式前加上歎號(!)取反。
  1. 更新
 git add 
 git commit
  1. 移除檔案
    git rm

檢視提交歷史

git log

撤銷操作---->程式碼回退

git reset HEAD <file>...

遠端倉庫的使用

  1. 檢視遠端倉庫
    git remote

你也可以指定選項 -v,會顯示需要讀寫遠端倉庫使用的 Git 儲存的簡寫與其對應的 URL。

  1. 新增遠端倉庫
    git remote add <shortname> <url>

  2. 從遠端倉庫中抓取與拉取

git fetch <remote>


git pull <remote> <branch>
// or
git pull

  1. 推送到遠端倉庫 git push <remote> <branch>
  2. 遠端倉庫的移除 git remote remove 或 git remote rm

git分支

git打標籤