C.A.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
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- robots: index, follow tags: NCTU, WDC, Git, 簡報 description: WDC Git 入門 lang: zh-tw dir: ltr breaks: true disqus: calee GA: UA-100433652-1 --- Git 入門 === ### Git / Git Server / Git flow ---- ![](https://git-for-windows.github.io/img/git_logo.png) https://hackmd.io/@calee/SJ_09kjf- ---- <img src="https://i.imgur.com/7px5IND.png" style="width:200px;height:200px;border-radius:50%"/> ### [李家安](https://www.facebook.com/calee0219) ##### 交大資工 大二 calee0219@cs.nctu.edu.tw - 網站開發社 - 網路安全策進會 - [NCTU CS Course](https://hackmd.io/CYFgpgDArBEIwFpgDYBGwEgOyog1YqAnAgGZwDMIqATCAByr1RhA) hosting --- ## 軟體開發 - 版本控制 - 團隊開發 ---- ### 什麼是版本控制? 教授要刻一顆 CPU,有 Cache 功能加十分 於是,有了漫長的旅程... ---- ![](https://denny.one/git-slide/img/code_smart_release-58.jpg)<!-- .slide: data-transition="fade-in" --> ---- ![](https://denny.one/git-slide/img/code_smart_release-68.jpg)<!-- .slide: data-transition="fade-in" --> --- ## 攻城屍的救星 版本控制 ---- ## 安裝 Git - `apt-get install git` - [windows 下載](https://git-scm.com/download/win) - [macOS 下載](https://git-scm.com/download/mac) - brew install git - [GitHub Desktop](https://desktop.github.com) ---- ## 環境設定 ```= git config --global user.email "you@example.com" git config --global user.name "Your Name" git config --global color.ui true git config --global core.editor vim git config --global alias.co commit git config --global alias.lg "log --color --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --" ``` ---- ## .gitconfig - [config file](https://git-scm.com/docs/git-config) - [ignore file](https://github.com/github/gitignore) - [large storage](https://git-lfs.github.com) - [我的設定](https://github.com/calee0219/.dotfiles/blob/master/gitconfig) ---- - man git - git help <command> - stackflow ---- ## 原理 git 會儲存每次的修改 藉由 hash 維護修改紀錄 hash value 會往上疊加 (前一個 hash + 修改) --- ## 開新專案 git init ---- ![](https://image.slidesharecdn.com/git-worfklow-drupal-core-dev-140302065209-phpapp01/95/a-git-workflow-for-drupal-core-development-14-638.jpg?cb=1393743243) [reference](https://git-scm.com/about/staging-area) ---- ## 新改變後... - git status - git diff - git add - git commit (-m) - git log ---- ### 何時 commit? ### 如何 commit? commit --amend --- ## Branch - git branch - git checkout -b ![](https://i.imgur.com/5ZxuOIZ.png) ---- ## Checkout - git checkout {branch name} - git checkout {commit hash} ---- ## Merge - git merge (--no-ff) - git rebase - git cherry-pick ![](https://i.imgur.com/qGF99ju.png) ---- ## submodule - .gitmodule - 紀錄 repo 位置 - 紀錄 commit - git submodule sync - git submodule init - git submodule update - git submodule update --init ---- ## Other trick - git stash (save / list / pop) - git blame - git tag - git format-patch -2 -o ./output - git am ./output --- # Git Server [GitHub](https://github.com) / [GitLab](https://about.gitlab.com) / [Gogs](https://gogs.io) / [Gitea](https://gitea.io/zh-TW/) / [BitBucket](https://bitbucket.org) / Etc... ---- ## 本地端版控 ![](https://denny.one/git-slide/img/18333fig0101-tn.png) ---- ## 集中式 ![](https://denny.one/git-slide/img/18333fig0102-tn.png) ---- ## 分散式 ![](https://denny.one/git-slide/img/18333fig0103-tn.png) ---- ![](https://denny.one/git-slide/img/local-remote.png) [Git Cheatsheet Cht](http://scars377.github.io/git-cheatsheet-cht/#loc=remote_repo) ---- ## 以 GitHub 為例 申請 [GitHub](https://github.com) 帳號 新增 repo - README.md ([Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)) - [License](https://www.openfoundry.org/tw/licenses) - [.gitignore](https://github.com/github/gitignore) ([Large file sortage](https://git-lfs.github.com)) - Public / Private ---- ## Git Clone - git clone (downstream / upstream) - git remote add origin https://... - git remote set-url origin git@://... - git remote (add / show / -v) - git fetch - git pull (fetch + merge) - git push (-u) ---- ## SSH vs HTTPS - git clone https://... - git clone git@... - ssh key (~/.ssh/id_rsa.pub) --- # X,東西寫炸了!! git clone https://github.com/calee0219/Frontier ---- ## 找戰犯囉~ - git log ( --author / --since= / --until= / regex) - git show - git blame ---- ## 尋找錯誤 - git diff - git difftool - git checkout ---- ## 暫存 - git stash - `git stash save "msg"` - `git stash list / show / apply / drop / pop` - [參考](https://git-scm.com/book/zh-tw/v1/Git-工具-儲藏-Stashing) ---- ## 工作目錄 - 創造出另一個工作目錄 (通常建再版控以外的地方) - `git worktree add -b branch /path/to/new/dir` - [參考](https://ihower.tw/blog/archives/8740) --- ## 復原 - git reset (\-\-hard) - git revert - [參考差別](https://github.com/geeeeeeeeek/git-recipes/wiki/5.2-代码回滚:Reset、Checkout、Revert的选择) - 只 reset 某一個檔案 - git checkout HEAD(commit) \-\- {file_name} ---- ## 刪除 untrack git clean (-f -d) --- ## Others - fork - submodule - issue - pull request / merge request - CI (Continuous Integration) - downstream / upstream --- # Git Flow - [git flow](http://nvie.com/posts/a-successful-git-branching-model/) - [github flow](https://guides.github.com/introduction/flow/) - [gitlab flow](https://about.gitlab.com/2014/09/29/gitlab-flow/) ---- ### Git Flow ![](http://lanziani.com/slides/gitflow/images/gitflow.png) ---- ### GitHub Flow ![](https://guides.github.com/activities/hello-world/branching.png) ---- ### GitLab Flow ![](https://about.gitlab.com/images/git_flow/environment_branches.png =450x) --- ## How about free5GC - submodule - upstream first - private repo - [Git workflow](https://free5gc.atlassian.net/wiki/spaces/FREE5GC/pages/144637953/Git+workflow) ---- ![](https://i.imgur.com/6lQYedJ.png =450x) ---- 0. `git clone --recursive git@bitbucket.org:free5gc-team/free5gc.git` 1. Open task 2. Create feature branch on submodule (NF/lib) 3. work & commit on submodule 4. Merge feature branch back to develop branch (using PR) 5. Create branch on `free5gc` (main repo) 6. Add develop commit of your feature 7. Merge branch to develop (using PR) --- ## 參考資料 - [Git](https://git-scm.com) - [完整學會Git GitHub Git Server的24堂課](http://www.books.com.tw/products/0010690010) - [Danny git 介紹](https://denny.one/git-slide) - [moztw 貢獻 快速指南](https://hackmd.io/EYRgnADAZgpgHAEwLRQEwgMZICxjMuYKOJAZlQRgQFZS4A2CU4IA?view) - [Code Smart, Don't Code Hard](https://speakerdeck.com/crboy/code-smart-dont-code-hard) - [為你自己學 Git](http://gitbook.tw/)

    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