ASTRO Camp 11th
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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
    # 20220815 Git/GitHub ###### tags: `github` `git` [TOC] github = 有好用介面的git伺服器 github 集中式管理 git 分散式管理 > https://git-scm.com/book/zh-tw/v2/開始-關於版本控制 > https: ![](https://i.imgur.com/n2xAE0E.png =350x) ssh: ![](https://i.imgur.com/cJQwakV.png =350x) ### clone (windows系統需要在WSL下才能clone專案, $ cd /mnt/d...) c槽不能寫入 ```shell git clone https/ssh ``` 將專案複製一份到本機 clone 只需要做一次即可,後續都是使用更新指令 後面追加名字 -> 複製且將資料夾改名為ccc ```shell git clone https/ssh ccc ``` ### fetch 線上有的,本機沒有的拉下來,並建立一個分支 遠端節點的名字/main ![](https://i.imgur.com/1Cqk3gU.png) ```shell= git fetch origin master git merge origin/master (待驗證 git merge origin) ``` ![](https://i.imgur.com/E7Ta6s5.png) ### pull 拉最新的commit下來 ```shell= git pull = git fetch + git merge ``` git merge才會發生衝突 git fetch只是把東西拉下來 ### push step1 New repository step2 填寫專案名稱(不能重複) step3 ```shell! git branch -M main 改名字 git remote add origin https://....... origin 可以換 ``` 遠端節點 ```shell! $ git remote -v //檢查線上節點 $ git remote rm hello kitty //刪除節點 ``` ### key SSH key 會有一對鑰匙 public key**(上傳至GitHub後,私鑰比對公鑰正確即可push成功)** private key**(不要隨便亂給)** #### 產生鑰匙 ```shell= # 查看ssh-key在哪 which ssh-keygen # 製作ssh-key ssh-keygen # 是否要更換檔名 沒有就按enter Enter file in which to save the key (/Users/zhangjianing/.ssh/id_rsa): # 設定密碼 Enter passphrase (empty for no passphrase): # ok Your identification has been saved in /Users/zhangjianing/.ssh/id_rsa. Your public key has been saved in /Users/zhangjianing/.ssh/id_rsa.pub. # 就會秀出key的圖片? The key fingerprint is: SHA256 ``` #### 查看鑰匙 ```shell= # 切到根目錄存放鑰匙的地方 cd ~/.ssh # 查看是否有公/私鑰匙 ls id_rsa* # id_rsa id_rsa.pub # 看公鑰 cat id_rsa.pub ``` #### github 設定鑰匙 ![](https://i.imgur.com/TfDbxv4.png) ![](https://i.imgur.com/u8AElmb.png) ![](https://i.imgur.com/MjaaK4X.png) ![](https://i.imgur.com/3m7l5NC.png) **電腦重灌或換電腦,直接把公私鑰匙搬過去就好哩 #### 設定公鑰後,就得用SSH推 git會拿私鑰去對github上的公鑰 對的起來就不用密碼 私鑰掉了,記得要去把網站上的公鑰撤掉 ### 2FA recover code ### 預設push特定遠端節點 ```shell= # 預設將main分支push到origin這個遠端節點 git push -u origin main # 下次push直接輸入 git push ``` 但`main`其實是簡寫 他的真面目是: ```shell! git push -u origin main:main ``` ```shell= # 把main推到origin上去,形成一個cat分支 git push origin main:cat ``` 用push刪除分支!! ```shell= # 刪除remote分支(刪除cat) git push :cat ``` ```shell= git push -u origin main ``` heroku只對main 或 master有反應 ```shell= git push heroku cat:main ``` ## 協作 pull(fetch + merge) request = PR Merge Request = MR fork 拉一份複製到自己的github ![](https://i.imgur.com/dSHyvUq.png) ### 發PR 當團隊在做專案時,除了發PR的人不用看以外,請大家!每個人!都要要嚴格地code review,**對別人仁慈就是對自己慘忍**。 接受pr後的選項: - merge - squash and merge=>恰恰~~XDD commit太鬆散就使用它 ![](https://i.imgur.com/WdMbAt6.png =400x) - rebase and merge 遇到更改同一個檔案時,發生衝突怎麼辦,關掉叫發pr的人重發啊!反正又不是我要修衝突~(老師口氣) 設定至少幾個人approve路徑 ![](https://i.imgur.com/pTFgWAV.png) ## 把大家加到同個專案中 大家在做專案時,可以規定大家用發PR的方式推上去,或是用dev來保護主線(main) (不是保護dev或main嗎?) dev不是開發時在用的? 但老師剛剛好像有說可以保護dev? 還是我有漏聽到? 可以問問看其他人哈哈哈哈哈哈! ## git flow > [淺談 Git Flow 與 commit 規範](https://israynotarray.com/git/20200914/1124442109) master跟feature一直都會在 ![](https://i.imgur.com/8p0CKPM.png) release 封測、內部測試 hotfix 緊急狀態下會出現 ## .git裡面有啥? * blob * tree * commit * tag Avalanche Effect https://www.oreilly.com/library/view/version-control-with/9781449345037/ch04.html ![](https://i.imgur.com/LyXyDD9.png) https://git-scm.com/docs/git-cat-file https://git-scm.com/book/en/v2/Git-Internals-Git-Objects ```shell! $ cat index.html | git hash-object --stdin ## 將結果秀出來 ``` 資料夾沒有內容 -> 無法計算結果 ```shell= $ git cat-file b8f3 -t ## type $ git cat-file b8f3 -p ## 內容 ``` commit是會變 每個commit都會指向上一個commit 只在乎檔案內容,不在乎檔案名字 ### DAG = Directed Acyclic Graph > https://web.ntnu.edu.tw/~algo/DirectedAcyclicGraph.html Git 不是[差異備份](https://docs.microsoft.com/zh-tw/sql/relational-databases/backup-restore/differential-backups-sql-server?view=sql-server-ver16) https://git-scm.com/docs/git-restore > The command can also be used to restore the content in the index with `--staged`, or restore both the working tree and the index with `--staged` `--worktree`. > By default, if `--staged` is given, the contents are restored from `HEAD`, otherwise from the index. Use `--source` to restore from a different commit. 暫存區>=儲存庫 git restore 檔案,資料是會從暫存區內撈 開分支很便宜 為什麼很便宜,因為他只是一個內含40個字元的文字檔案 ```shell! $ git checkout HEAD^2 是往上一層的第2個parent退 ```

    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