Skip to content

Note

不挑戰記憶力的技術筆記

Menu
Menu

Git安裝及建置環境、常用指令

Posted on 2014 年 5 月 3 日 by febr

官網:http://git-scm.com/
離線版文件:C:Program Files (x86)Gitdocgithtml
使用VS2012更新到update 3,可另外安裝使用Git套件

安裝Git for Windows時,到 Adjusting your PATH environment 步驟時,
選擇 『Run Git from the Windows Command Prompt 』這個選項,相容性比較高,之後出現的問題較少

選項設定:
第一次使用必要設定:

git config --global user.name "yourusername"
git config --global user.email "yourmail@mail.com"

1. 執行環境的層級分類:
設定層級分為下列三層,套用優先權為(高至低):儲存區層級 > 使用者層級 > 系統層級
通常會用到使用者層級,設定指令和設定檔路徑分別為:

(1) 系統層級(System-level configuration):

git config --system --list

#C:\Program Files (x86)\Git\etc\gitconfig

(2) 使用者層級(User-level configuration)

git config --global --list

# C:\Users\<使用者帳號>\.gitconfig

(3) 儲存區層級(Repository-level configuration)

git config --list  #顯示所有層級的參數,越下方的參數,優先權越高

#<Git儲存目錄>\.git\config

git config 選項  #指定選項的value,此值為套用所有層級後的結果

#刪除指定選項的value

git config --unset 選項  #(刪除儲存區層級的value)
git config --global --unset 選項   #(刪除使用者層級的value)

.gitignore: 忽略清單,在清單中的檔案將不會被commit

使用前須知:
git的狀態:
staged: 已經add,將要被commit的檔案
not staged: 檔案有變更,但沒有被add
untracked: 尚未被追蹤,所以也不會被commit
如果更改檔名,但檔案內容不變,則會被視為rename

常用指令:

git --version  #取得版本
git init  #初始化git目錄
git status
git add . 
git add <filename>
git add -u  #只加入有變更過的檔案
git add -A <filename>  #所有檔案標示為staged
git commit -m "message"
git commit --amend  #取消上一次的commit,但版號不變。
git log
git blame 程式名稱 #找出某支程式的修改歷程
git rm <filename>
git reset -- <filename>  #把Stage的file給UnStage,變為Untracked(檔案內容不會修改)
git checkout -- <filename>  #Undo changes(於not staged的狀態,回復到上一個版本的檔案)("--"="HEAD")
git clean -n  #列出需清空的檔案(Untracked files)
git clean
git diff  HEAD #與最新版本比較
git diff --staged
git diff HEAD~1..HEAD  #倒數第二版與最新版的比較
git diff <CommitID1>..<commitID2>  #透過Hash過的commit id來比較兩版本的差異

在本機建立共用的儲存庫 (shared repository):

git init --bare

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

近期文章

  • [AWS] S3 Object Initiate restore (復原回 Standard)
  • [Windows] 使用者快速登出的方法 Logout/ Logoff/Sign Out from Windows User Account
  • [Windows] Windows 11 安裝Server管理工具Install RSAT(Remote Server Administrator Tools)
  • Chrome出現:你的連線不是私人連線 Your connection is not private
  • [C#] 取得 Request URL 的方法

近期留言

    彙整

    分類

    • Ajax
    • Android
    • ASP
    • ASP.NET MVC
    • Azure
    • C#
    • Cisco
    • CSS
    • Delphi
    • Developer Tools
    • Framework
    • FreeBSD
    • Git
    • HTML5
    • javascript
    • jQuery
    • Juniper
    • Linux
    • Mac
    • PHP
    • Python
    • Server&OS
    • Software
    • SQL server
    • Sublime Text
    • Ubuntu
    • Visual Studio
    • Vmware
    • Web Design
    • Web Development
    • Windows
    • WordPress
    • 未分類
    • 未分類

    彙整

    分類

    • Ajax
    • Android
    • ASP
    • ASP.NET MVC
    • Azure
    • C#
    • Cisco
    • CSS
    • Delphi
    • Developer Tools
    • Framework
    • FreeBSD
    • Git
    • HTML5
    • javascript
    • jQuery
    • Juniper
    • Linux
    • Mac
    • PHP
    • Python
    • Server&OS
    • Software
    • SQL server
    • Sublime Text
    • Ubuntu
    • Visual Studio
    • Vmware
    • Web Design
    • Web Development
    • Windows
    • WordPress
    • 未分類
    • 未分類

    其他操作

    • 登入
    • 訂閱網站內容的資訊提供
    • 訂閱留言的資訊提供
    • WordPress.org 台灣繁體中文
    © 2025 Note | Powered by Superbs Personal Blog theme