莨
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Git使用教學 | [官方文件](https://git-scm.com/book/zh-tw/v2/%E9%96%8B%E5%A7%8B-%E5%88%9D%E6%AC%A1%E8%A8%AD%E5%AE%9A-Git) ==前言== >Git是一個 「分散式版本控制軟體」,在軟體開發領域,對原始碼進行版本控管是非常重要的一件事。 >>不過 Git 的指令與參數非常多,除非每天使用,學習 Git 概念後,最後還是使用 GUI 工具比較方便。 ==Git 的好處== * 參與 Git 開發的每個人,都將擁有完整的開發歷史紀錄 * Git 不會因為專案、檔案變大,導致速度變慢 * 歷史紀錄保護 * Git 的垃圾回收機制 ( 手動:`git gc --prune` ) * 定期的封裝物件 ## 本地數據庫 Local Respository 安裝流程 1. [Git 官網](https://git-scm.com/) 2. 選擇對應版本下載 Git 並安裝 3. 打開「Git Bash」或「命令提示字元」或「PowerShell」 4. 輸入指令 **`git --version`** 確認是否安裝成功,系統會回饋安裝版本編號 5. config 設定姓名、Email ``` git config --global user.name "您的姓名" git config --global user.email "您的Email" git config --list //查詢設定 ``` 6. 按 `q` 離開 7. 建立本地端數據庫 1. 電腦上新增資料夾 2. 透過 `cd` 前往資料夾 working directory 3. 執行 `git init` 4. 回饋以下訊息,建立成功 5. 會在資料夾內建立一個 `.git` 的資料夾 ``` $ git init Initialized empty Git repository in "專案路徑"/.git/ ``` 3. `git status` 查詢指令 1. `Untracked files` 是 Git 偵測到新增檔案,但 Git 尚未追蹤 2. `git add <檔案名稱>` 將它加入到 `staging area` 索引 裡面 3. `git add .` 全部加入索引 staging area 4. `Changes to be committed` 放在索引檔案即將提交成一個新版本 `commit` 5. `git commit -m "<填寫版本資訊>"` 提交新版本 6. `git status` 得到以下資訊,提交成功 ``` On branch master nothing to commit, working tree clean ``` 4. `git log` 查詢版本 5. 之後新增修改只需要從 `git add .` 開始推到索引庫,再新增版本 `git commit -m "<填寫版本資訊>"` ### config 位置 | [官網](https://git-scm.com/book/zh-tw/v2/%E9%96%8B%E5%A7%8B-%E5%88%9D%E6%AC%A1%E8%A8%AD%E5%AE%9A-Git) 輸入指令時,是針對一個實體檔案去做修正 `.gitconfig` • Windows:`c:\documents and settings\user\` ### 終端機指令 在終端機上,可以移動專案資料夾的位置 `cd C:\Users\使用者名稱\Desktop\project` 也可以輸入 `cd` 後拖曳資料夾 ### 基本指令架構 ![](https://i.imgur.com/5XUUIPo.png) ### Git 常用指令 * 初始化數據庫: git init * 開啟 .git 隱藏檔方案 (https://helpx.adobe.com/tw/x-productkb/global/show-hidden-files-folders-extensions.html) * Mac `command+shift+.` * 查詢當前狀態:git status * 要將檔案加入到指定資料夾 * 將檔案加入到索引:git add . * 將索引檔案變成一個更新(commit):git commit -m "新增網頁環境" * 觀察 commit 歷史紀錄: git log * 下載遠端數據庫: git clone 數據庫網址 * 更新遠端數據庫: git push origin master ![](https://i.imgur.com/Cnb7izq.png) ## 工作狀態還原技巧 ### Git 版本細節 * branch :分支,預設分支叫做 master * HEAD:指標 * origin:預設遠端儲存庫名稱 * 回頭觀看版本內容:git checkout 編號 * 返回最新的版本:git checkout master(分支名稱) --- ## git branch 分支 > 分支的好處在於當多人同時使用專案時,大家可以針對這個專案各自建立自己的分支,如此一來每個人都可以先在自己的檔案上編輯,之後完成可以再一起合併。 ### 1.建立分支 `git branch [分支名稱]` ![](https://ithelp.ithome.com.tw/upload/images/20211002/20141010FkA9C9Kj34.png) ### 2.查看分支 `git branch`/`git branch --list` 查看當前專案的分支有哪些,*代表目前處在的分支 ![](https://ithelp.ithome.com.tw/upload/images/20211002/20141010hay16N55qo.png) ### 3.切換分支 `git checkout [分支名稱]` ![](https://ithelp.ithome.com.tw/upload/images/20211002/20141010DMZEaIJMwI.png) ### 4.同時建立與切換分支 `git checkout -b [分支名稱] ` ### 5.重新命名分支(本地) `git branch -m [舊名稱] [新名稱]` ![](https://ithelp.ithome.com.tw/upload/images/20211002/20141010H1RoD0rYJx.png) ### 6.刪除分支 `git branch -d [分支名稱]` :warning: -D 參數: D 為強制刪除之意。 ![](https://ithelp.ithome.com.tw/upload/images/20211002/20141010McaYgRx4pl.png) [分支參考文章1](https://ithelp.ithome.com.tw/articles/10276132?sc=hot) [分支參考文章2](https://ithelp.ithome.com.tw/articles/10211790) ### 7.合併分支 - git merge - fast-forward --- #### git merge - 自動合併篇 #### git merge - 解決衝突篇 ### git tag - 標籤 ### git stash - 暫存檔案 ### HEAD - 了解目前所在位置 ## Git GUI 介面工具 ### **Sourcetree | [影片教學](https://www.youtube.com/watch?time_continue=579&v=qAowFThM50c&feature=emb_title)** > 由 ATLASSIAN 開發的工具,是一套非常專業的 GUI 操作工具。 > 支援 Git、Mercurial 這兩套版本控管機制都屬於分散式版本控管的分類,概念十分相近,可以整合在這一套工具上使用。 取代指令 window 跟 mac 的介面不一樣 1. 使用 `add` 加入專案 2. 可以再 History 頁籤視覺化git flow 3. 打勾把新增的檔案加入索引 4. 再新增 commit 後推到數據庫 ### **GitHub Desktop | [安裝流程](https://github.com/doggy8088/Learn-Git-in-30-days/blob/master/zh-tw/02.md)** 由github官方開發的工具,寫給那些對 Git 沒有很了解的人用的。 主要功能 : 1. Clone Repositories - 將 GitHub 上面的儲存庫複製回來 (git clone) 2. Browse History - 瀏覽本地儲存庫的版本歷史紀錄 3. Commit Changes - 提交變更到本地儲存庫 4. Branch Code - 建立與管理 Git 分支,還可以在工作目錄中切換分支 5. Share on GitHub.com - 與 GitHub 同步變更這裡「同步」 (Sync) 的意思是將 git pull 與 git push 整合在一起 - GitHub for Windows 在同步的時候,預設是使用 rebase 方式進行合併。 > 若開發大型專案需考慮是否這些功能就可滿足需求

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully