AstroCamp 6th
      • 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
    2
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 1027_git_day2 [![hackmd-github-sync-badge](https://hackmd.io/PbWvPH__SjqmEO2J_q_MNg/badge)](https://hackmd.io/PbWvPH__SjqmEO2J_q_MNg) #### 上課日期:1027 ###### tags: `git` ###### tags: `5xruby` --- # 相關連結 - [課程影片](https://campus.5xruby.tw/courses/1136422/lectures/25307238) --- # 目錄 - [工作區、初始化](https://hackmd.io/PbWvPH__SjqmEO2J_q_MNg#Git%E5%88%86%E4%B8%89%E5%A4%A7%E5%8D%80%E5%A1%8A%EF%BC%9A%E5%B7%A5%E4%BD%9C%E5%8D%80%E3%80%81%E6%9A%AB%E5%AD%98%E5%8D%80%E3%80%81%E5%84%B2%E5%AD%98%E5%BA%AB) - [標籤、貼紙](https://hackmd.io/PbWvPH__SjqmEO2J_q_MNg#%E6%A8%99%E7%B1%A4--%E8%B2%BC%E7%B4%99) - [GitHub](https://hackmd.io/PbWvPH__SjqmEO2J_q_MNg#GitHub%E6%98%AF%E4%BB%80%E9%BA%BC%EF%BC%9F) - [作業](https://hackmd.io/PbWvPH__SjqmEO2J_q_MNg?both#%E4%BD%9C%E6%A5%AD) - [附錄](https://hackmd.io/PbWvPH__SjqmEO2J_q_MNg#%E9%99%84%E9%8C%84) > 上面連結點了會另開連結... --- ### Git分三大區塊:工作區、暫存區、儲存庫 ### 初始化git - 在欲版控的根目錄下,執行`git init`,再執行`ls -al`會發現多了一個.git的隱藏檔案,所有在這個根目錄下的檔案更動都會紀錄在裡面。 - 用指令`git status`可以看到所在位置的目錄下,是否有檔案未被追蹤,可使用git add加到暫存區以進行追蹤。有任何資料異動,也會顯示在這裡 ### 初始化後的檔案每次想要儲存都要做以下的事情 1. $ git add 檔案名(想全存就使用".") 2. $ git commit -m "這次commit的說明"(沒有-m就會掉進vim的深淵喔!) ```ruby $ git status 位於分支 human 尚未暫存以備提交的變更: (使用 "git add/rm <檔案>..." 更新要提交的內容) (使用 "git restore <檔案>..." 捨棄工作區的改動) 修改: djiwd.html 刪除: hello.html 未追蹤的檔案: (使用 "git add <檔案>..." 以包含要提交的內容) aaa.html ``` :::info ### 不小心掉進Vim怎麼辦?(救救我) Git內建的編輯器-Vim,有兩個模式: * Normal 模式(命令模式)-逃脫方法 離開 :q 存檔 :w 存檔後離開 :wq (冒號必打) * Insert 模式(編輯模式)-逃脫方法 操作前要按i或o或a其中一個,按ESC鍵可以退到命令模式 ::: ### 快捷鍵 - `cd /` 回到c槽(如果使用window要用cd /mnt/c/) - `cd -` 回到上一次操作 - `ctrl + W` 一個字一個字刪除(空格到空格是一個字) - `ctrl + u` 整行刪除 - `ctrl + l` 整個版面清理 - `ctrl + r` 尋找曾經下過的指令 ### 分支 - `cd /` 回到c槽(如果使用window要用cd /mnt/c/) - `cd -` 回到上一次操作 - `git checkout -` 更換head到上ㄧ次 - `$git commit -m "ccc" --allow-empty` 允許註解空白 - 快轉合併(fast-forward) ## 分支(貼紙) ### 分支(branch)改名 `git checkout -` 將HEAD回到上一個分支位置(兩個互換) `git branch` 可以查詢目前分支 `git branch -d` 可以刪除分支/標籤 `git branch -m` 改分支/標籤名 `git branch -f` 可強制移動分支 `git merge `(現在分支)(欲走到的分支位置) ### 刪除分支 - 留著也沒關係,因為只是一個標籤/貼紙,容量很小(幾kb=幾千byte),沒什麼實際的影響,不影響主枝幹。 - 刪除未合併分支,並沒有實際刪除,只是隱形。(git沒有刪除這回事) ### tag標籤 > 使用代號的意思 > 通常用在重要的commit/里程碑 ``` $ git tag 1.0.0 51d54ffc,其中1.0.0是自己設定的標籤 ``` ### 發生衝突 1. 發生在合併之後 2. 查看衝突的檔案,`$ git status` 5. 修改衝突的檔案(在文字編輯器裡,如vscode) 6. 將修改後檔案加到暫存區,`$ git add xxxx.html` 7. 將修改後檔案加到儲存庫,`$ git commit -m "add xxxx"` --- ### head - `$ git reflog` = ref+log,查看紀錄:檢視head的移動軌跡 - 會移動head的操作 * checkout * commit * reset * merge --- ### Rebase 另一種合併的方式(剪貼?嫁接?) - rebase跟merge的差異就是: - rebase有點像身為HEAD的貼紙,去踩著另一個貼紙往上爬的感覺; - 而merge則是再多開一個commit,把不是HEAD的那個節點加進來的感覺 - 操作練習 ``` # use branch2 $ git checkout cat $ git rebase dog ``` :::info **注意**: 如果使用是windows的同學,可能會有電腦解讀問題,說有沒有add的檔案而不讓你操作合併分支,可打以下指令解除: `$ git config core. filemode false` ::: ### reset / become - 同時搬移分支及HEAD,回到指定位置(代名詞)的狀態 - 使用參數 ``` --mixed:預設值,丟回工作目錄 --soft:丟回暫存區 --hard:丟進垃圾桶 ``` ``` ^ = caret 倒退一步 ~n = tilde 倒退n步 ex: head^^ = head~2 ``` - 有兩個parent時: ^1:往1st parent移動 ^2:往2nd parent移動 - checkout 只移動head,但reset會移動head和分支 ### 使用標籤(tag) * $ git alias(別名) ``` $ git config --global alias.co checkout $ git config --global alias.br branch $ git config --global alias.st status ``` * tag:通常用在里程碑 標示階段 * 分支:通常用來區別功能 * tag和分支的差異:tag不能移動只能刪除,分支可以移動可以刪除。 --- ## GitHub是什麼? - [練習用專案](https://github.com/kaochenlong/git-demo-123) ### 用push把你的專案上傳GitHub吧 `$ git push origin master` > (你不想用origin也可以用其他名稱,但自己要記得) `$ git push origin master:master ` > (前面的master代表你本機的貼紙;後面的master代表你上傳後想叫甚麼貼紙) `$ git push origin 1.0:abc ` > (這個表示你想要把標籤1.0的commit上傳而且貼紙名稱改成abc) ### Heroku > 未來你也許會使用到的平台;他要求你一定要使用master貼紙 ``` $ git push heroku master $ git push heroku cat:master ``` - 如果你調皮本機不想要上傳master貼紙也沒關係,只要上傳cat貼紙時跟他說雲端要改用master貼紙喔,這樣這個平台也給過 ### 如果想把git改成英文版的話 ``` $ echo "alias git='LANG=en_GB git'" >> ~/.zshrc ``` 在終端機上輸入上列指令,然後重開就可以了。 ### 如果想延長打字的壽命的話 ``` $git config --global alias.co checkout $git config --global alias.br branch $git config --global alias.at status ``` 以上是幾個簡單的縮寫替代,從此就靠co幫你checkout;st幫你status;br幫你branch --- --- # 作業 ## 別忘了回家作業 11/2 前要交! - [回家作業下載連結](https://ubin.io/git-q-example) --- ## 附錄 ### 筆記工具 HackMD - [HackMD](https://hackmd.io/):台灣新創,使用markdown語法,也可用html標籤(部分?) - [markdown語法參考(Astrocamp粉專)](https://reurl.cc/gmN5eX)

    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