Lawrence Chou
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • 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 No publishing access yet

        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.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        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 No publishing access yet

    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.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    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
    # c4Lab Git tutorial ###### 2017/07/18 @ 台大生機系 ## Schedule - **Part 0** 準備 - **Part 1** 基礎觀念、名詞解釋及常用指令 - **Ex 1** 從 pull 到 push - **Part 2** Git協作:branch和merge - **Ex 2** 現場多人協作練習 - **Part 3** IDE的git整合(以PyCharm為例) - **Part 4** 進階主題 ## Part 0 準備 **TODO 1:確認已安裝git** `必備` https://git-scm.com/book/zh-tw/v1/開始-安裝Git hint: 安裝前、安裝後以 `$ git --version` 檢查是否已安裝 - 開啟 Git Bash(win) 或 terminal(mac, linux) - 執行 `git clone https://github.com/choznerol/c4lab-git-tutorial.git` 抓今天的教材 - 還沒裝好:https://vdi.ntu.edu.tw/portal/webclient/index.html#/desktop **TODO 2:註冊GitHub帳號(或找回密碼XD)** `必備` https://github.com/login - 填寫你的 GitHub username: - **TODO 3:下載安裝 PyCharm** `自由選用` 好用又好看的python IDE,會demo它的版控功能,推薦給常在本機寫python的同學 https://www.jetbrains.com/pycharm/download/ **TODO 4: 下載安裝 GitKraken** `自由選用` 個人覺得最好用的Git的GUI,會demo它帶觀念,推薦給git新手&常在本機用git協作的同學 https://www.gitkraken.com/download ## Part 1 基礎觀念及常用指令 ### Git是啥 - Git v.s. Dropbox - 版本控制:commit、branch、程式隨時可動 ![](https://i.imgur.com/EUkzyjy.png =200x) - 分散式:各自離線作業、需要再merge ![](https://i.imgur.com/WKkfgl6.png =200x) ### 不錯的學習資源 - [Try Git](https://try.github.io/levels/1/challenges/3):GitHub的線上互動式git練習(15min) - [連猴子都能懂的 Git 入門指南](https://backlogtool.com/git-guide/tw/intro/intro1_1.html):中文的詳盡主題式Git指南 - [Git 名詞解釋](http://dylandy.github.io/Easy-Git-Tutorial/):想知道什麼是reference、snapshot、HEAD? - [Pro Git](https://git-scm.com/book/zh-tw/v1):官方的git聖經本(?) ### 基本架構 ![](https://i.imgur.com/GMCW0xW.png =500x) 四個工作區:**Working Directory / Staging Area / Local Repository / Remote Repository** 三種檔案狀態:<span style="color:red">modified</span> ---(add)---> <span style="color:green">staged</span> ---(commit)---> <span style="color:gray">committed</span> **Staging Area** (noun.) *a stopping place or assembly point en route to a destination.* Q:Git = GitHub ? A:錯誤,GitHub、GitLab、BitBucket都是'remote repository' ### Git基本指令 ![](https://i.imgur.com/o029SMu.png) - **add**:將working directory的modified file加入staging area ``` $ git add <filename1> <filename2> $ git add *.png || dirname $ git add . //一次stage所有更動 $ git add -i //interactive ``` - **commit**:將目前在staging area的所有staged file做成一個版本快照,提交到repository ``` $ git commit -m "我修改了某某feature" // $ git commit --amend // ``` - **push**:將local repo的commit同步到remote repo上 ``` //如果從 git clone 開始的 $ git push //失敗請檢查 git remote -v ``` ``` //如果是用 git init 開始的 $ git remote //看看你有沒有 remote repo,沒有的話去 GitHub 創一個 $ git remote add origin git://github.com/johndoe/myproject.git $ git remote -v origin git://github.com/schacon/ticgit.git ``` - **git pull**:從remote repo把線上的最新版抓下來 `$ git pull` `$ git pull --no-ff` - **status**:隨時檢查三個工作區的狀態 `$ git status` - **log**:檢視commit歷史 `$ git log` `$ git log --graph //顯示線圖` `$ git log --graph --oneline //顯示線圖、精簡commit資訊` ### 從GUI上感受一下(demo) ![](https://i.imgur.com/rlSYRu5.png =500x) ## Ex 1 從 pull 到 push **Step 1** 在 [TODO2](https://hackmd.io/MYTgbA7AzADApgDgLRwhArEgLAMxiJAIyh0JRgEZCEZ1ItEg?both#part-0-準備) 留下你的GitHub username,讓我把你加為專案的collaborator(取得push到remote repo的權限*),然後去收信 **Step 2** 在本機設定user資訊,才知道是誰commit的 ``` $ git config --global user.name "John Doe" $ git config --global user.email "jdoe@mail.com" $ more ~/.gitconfig // 偷看一下其它 config 有什麼 $ git config --global color.ui true $ ... ``` **Step 3** 從remote repo把一個專案clone下來開發 ``` $ git clone https://github.com/choznerol/c4lab-git-tutorial.git $ cd c4lab-git-tutorial // 進入working directory $ ls -al // 觀賞一下git專案的目錄 $ cd exercise-1_from-pull-to-push // Ex1目錄 $ vim myusername.py // 以你的username建立一個檔案 $ git status // 紅色是modified file,綠色是staged file ``` **Step 4** ``` $ git add myname.py // stage你的更動 $ git commit -m "Added myname.py" // 輸入有意義的commit訊息 $ git log // 檢查 ``` ### 觀摩一下複雜版 ![](https://i.imgur.com/ucdEiiw.png =500x) ## Part 2:Git協作:branch和merge ![](https://i.imgur.com/WQqgP9s.png =500x) ``` $ git branch //顯示目前有的分支 $ git branch my-branch //創一個新分支` $ git checkout my-branch //切換到new-branch $ git checkout master //切換回到master分支 $ git checkout -b feature-1 //創一個分支並切換過去 $ git merge my-branch //把new-branch merge回目前所在分(master) //編輯檔案解決conflict $ git commit -m "merge my-branch into master" $ git branch -d my-branch //刪除my-branch ``` push失敗: ![](https://i.imgur.com/8Rtqn0k.png) ## Ex 2 現場多人協作練習 開一個 branch 編輯`ex2-coworking.py`加入自己的名字,嘗試merge直到成功push ``` $ git checkout -b adding-john $ vim ex2-coworking.py //加入你的名字 $ git add ex2-coworking.py $ git commit -m "Add john to ex2-coworking.py" //在adding-john上commit $ git checkout master //切回master準備merge $ git merge adding-john //把adding-john分支merge進來(master) $ git pull //若pull回來有衝突就再次編輯檔案解決 $ git push //若失敗就再pull ``` ## Part 3 IDE的git整合(以PyCharm為例) - Why use IDE? - Debugger([使用教學](https://www.youtube.com/watch?v=QJtWxm12Eo0&index=7&list=PLQ176FUIyIUZ1mwB-uImQE-gmkwzjNLjP)) - Refactor - 整合版本控制([基礎](https://www.youtube.com/watch?v=_w9XWHDSSa4&index=12&list=PLQ176FUIyIUZ1mwB-uImQE-gmkwzjNLjP)、[進階](https://www.youtube.com/watch?v=AHkiCKG-JhM&index=13&list=PLQ176FUIyIUZ1mwB-uImQE-gmkwzjNLjP)) - Demo! - PyCharm官方教學([播放清單](https://www.youtube.com/playlist?list=PLQ176FUIyIUZ1mwB-uImQE-gmkwzjNLjP)) ## Part 4 進階主題 - 不是Collaborator怎麼協作? 發PR - Private repo?[GitHub Student Package](https://education.github.com/pack) - Git共享巨大檔案?[Git LFS](cyruschiu.github.io/2016/09/26/using-git-lfs/) 或用 dropbox 加 wget - 每次push都要輸帳密好麻煩?[設定ssh-key](https://git-scm.com/book/zh-tw/v1/%E4%BC%BA%E6%9C%8D%E5%99%A8%E4%B8%8A%E7%9A%84-Git-%E7%94%9F%E6%88%90-SSH-%E5%85%AC%E9%96%8B%E9%87%91%E9%91%B0)

    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
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    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