Ryan Lee
    • 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
    • Engagement control
    • 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 Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control 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
    2
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    Git Bare Repo === ###### tags: `git` `GSS` ## 前言 遇到一個情境是需要將 Subversion 上的專案搬到 Git 上,但原本的 Subversion 將會有其他人繼續開發,而 Git 上後續變更的內容將不會推回 Subversioin 上,但 Subversion 上的版本將不會頻繁地更新回 Git 上,所以更像是 Subversion **單向** 的更新/匯出到 Git 上。 在使用 **subgit** 工具轉換時,Subversion 轉出來的是一個 Bare Repo,故有了此篇的 Bare Repo 簡介。 詳情: [Subversion to Git](https://hackmd.io/@hbdoy/By5D89GsH) 基本 Git 教學: [Git 筆記](https://hackmd.io/@hbdoy/By5kZvuzx) ## 簡介 Git 儲存庫 (Git Repository) 大致可以分為三種 * 本地的儲存庫 (local repository) * 共用的儲存庫 (shared repository) * 遠端的儲存庫 (remote repository) 其實都是差不多的東西,Git 是分散式的版本控制,所以只是放置的位置、使用者不同而已。 ## local repository ``` $ git init myproject $ cd myproject $ ls .git/ ``` 用 ``init`` 不帶參數新增的專案包含: 工作目錄 (Working Directory) + Git 儲存庫 (Git Repository) - **工作目錄**: 放置程式的地方,ex: ``.py``、``.js`` 的檔案 - **Git 儲存庫**: ``.git`` 資料夾 ## remote repository 常見的託管平台: github、gitlab、BitBucket、...etc 遠端已經存在的專案 ``` $ git clone http://github.com/hbdoy/xxx ``` 將 local 的 repo 首次提交 ``` $ git remote add origin https://github.com/hbdoy/xxx.git $ git push -u origin master // also you can use $ git push --all $ git push --tags // or $ git push --mirror ``` 若遠端的 repo 網址改變,可以修改 origin 位址 ``` $ git remote set-url origin https://github.com/hbdoy/new_xxx.git ``` ## shared repository 和 ``remote repository`` 差不多,都可供多人同時使用開發,實作上也可以理解為 **Git Bare Repo** (裸庫) ``` $ git init --bare bareproject ``` 不同於上面,**Bare Repo** 只有 **Git 儲存庫** (Git Repository) 而已,也就是沒有 **工作目錄**,因為沒有程式檔案,所以你無法在上面 ``git add``、``git commit``,他的用意也不是要讓你在上面開發的。 **Bare Repo** 雖說有 Git 儲存庫,但他沒有 ``.git`` 資料夾,而是將裡面的內容直接放到專案根目錄下,專案的資料夾名稱習慣會在最後面加上 ``.git``,EX: bareproject.git ``bareproject.git/`` ![](https://i.imgur.com/6HnALGV.png) 對比一般含有工作目錄的 Repo ![](https://i.imgur.com/F04bU4k.png) :::success Bare Repo 的儲存庫內容物其實不完全等於 ``.git`` 中的東西,``.git`` 還會包含一些工作目錄下的資訊,而這些資訊不會放到 Bare Repo 中 ::: ### 用途 **Bare Repo** 像是一個 Git Server,可以讓別人 clone 下來開發,開發完再 push 回去,比起上面兩者是用來開發(工作)用的,Bare Repo 是用來分享(共享)的,而且沒有存著程式檔案,整個專案資料夾容量較小。 ### 情境 - 在 Linux 上建立 Bare Repo,讓數個開發者透過 ssh 來存者這個資料夾,進行 clone & push 等操作 > 如何在 Linux 上建立 Remote Bare Git Repo 可參考: 1. https://blog.gtwang.org/linux/linux-git-server-using-ssh/ 2. https://stevenitlife.blogspot.com/2015/02/repository.html - 或是建立在其他資料夾同步軟體,EX: Google Sync、Dropbox ### 差異 - **一般 Git Repo** 用來開發,工作目錄存著``程式檔案``、儲存庫記錄著所有``檔案的版本訊息`` - **Bare Repo** 用來單純紀錄``檔案的版本訊息``,中心點上建立一個 Bare Repo,所有專案成員可以 push 自己編輯的版本訊息到這個 Repo ## Bare Repo 常用指令 ### 建立 #### local ``` $ git --bare init xxx ``` #### 將 Remote Repo 轉成 Bare Repo ``` $ git clone --bare http://github.com/hbdoy/mypoject ``` ![](https://i.imgur.com/W5pf3Zk.png) ![](https://i.imgur.com/08xzlcL.png) ### Clone #### Clone From Bare Repo 此處示範 clone 本地上的 bare repo ``` $ git clone roulette.git ``` ![](https://i.imgur.com/KNtY4Yp.png) 可以看到 Bare Repo Clone 出來的專案自動長出工作目錄 ![](https://i.imgur.com/NBKbWLA.png) 但要注意他的 origin,若要推到其他 remote repo 記得修改 ![](https://i.imgur.com/2OqSZmy.png) ### Push #### Push to Bare Repo 延續上方的 clone from local bare repo ``$ cd roulette/`` 1. 在 ``roulette`` 下新增一個 ``test.txt`` 檔案 ![](https://i.imgur.com/cyhFhY1.png) 2. git add、git commit 3. git push (to bare repo) ![](https://i.imgur.com/N6awIra.png) 進入一開始 clone 來源的 bare repo ``$ cd roulette.git/`` 此時可以看到剛剛 clone 來源的 bare repo: ``roulette.git`` 已經多了一個 git log ![](https://i.imgur.com/iebcrXW.png) 但是一樣不會看到 ``test.txt`` 檔案 ![](https://i.imgur.com/Oo3xbD0.png) ### 搬遷 Remote Git Repo 情境 #### 本地沒有完整專案 不需要 clone 一大包東西下來,可以 clone 一個 bare git repo (只有 git 儲存庫),再推到新位址去就好 ``` $ git clone --bare https://github.com/hbdoy/xxx ``` ``` $ cd xxx.git $ git push --mirror https://github.com/hbdoy/new_project ``` ### 參考文件 https://blog.csdn.net/pcplayer/article/details/72784096 https://ithelp.ithome.com.tw/articles/10132804 https://www.saintsjd.com/2011/01/what-is-a-bare-git-repository/

    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