蔣汶儒
    • 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
    --- tags: tutorial, ss, ncu author: N0-Ball title: Git slideOptions: theme: solarized transition: 'fade' GA: UA-208228992-1 --- # git --- # ECHO $(WHOAMI) ---- ## №Ball ### 太空三 ---- ## Todays slide ![](https://i.imgur.com/QMY8kh1.png) ---- ## Before that ```sh git --version ``` --- ## What is git? [Advanced git](https://github.com/doggy8088/Learn-Git-in-30-days) ---- ### Let's assume that you have a program. ###### Called FinalProject ---- ## How do you often store your data? 1. FinalProject_V1 2. FinalProject_V2 3. FinalProject_V3 4. FinalProject_V100000000 5. FinalProject_FINAL ---- ## How do you often store your data? 1. FinalProject_V1 2. FinalProject_V2 3. FinalProject_V3 4. FinalProject_V100000000 5. FinalProject_FINAL 6. FinalProject_FINAL2 7. FinalProject_FINAL3 8. FinalProject_FINAL10000 ---- ### What if you are trying to cooperate with classmates? 1. FinalProject_V1_EVIL 2. FinalProject_V1_STAR 3. FinalProject_V1_TSAI 4. FinalProject_V1_MERGE 5. FinalProject_V1_MERGE2 6. FinalProject_V1_MERGE3 ---- ### Moreover #### Do you even know the different between V4 and V1? ---- ### Moreover #### What if someone changed and somehow the program just doesn't work where CRTL+Z doesn't help you? ---- ## What is git? :::info A version controller ::: --- ## How to git? ---- ### As a master said before > you can make great products from an application by only using 20% of its functions. *You only need to know the basics* ---- ### Basic `STAGES` of git ![](https://i.imgur.com/ectgKSZ.jpg =500x400) ---- ### Basic `STAGES` of git - Working Directory -> Where you write your code - Staging Area -> **Magic** - Local Repo -> git on your computer - Remote Repo -> git not on your computer ---- ### What is a Repo? `Repository` which you can see as a project file (often a directory) ---- ## Review What is the stage that you write your codes? ---- ### Working Directory ```bash mkdir gitPractice # Make an new directory cd gitPractice # Go to the directory ``` ---- ### Working Directory #### Creating one ```bash git init ``` #### Result ```shell Initialized empty Git repository in $(pwd)/.git #you can do "echo $(pwd)" to verify if the command is correct ``` ---- ### Go ahead an play make changes ```bash echo "Never Care U" > NCU # This will create a file called `NCU` with content "Never Care U" ``` ---- ## Quick Review After finishing a period, what stage will you want to enter ---- ### Staging Area :::success OFTEN USED COMMAND ::: ```bash git status ``` ##### Results 1. What `branch` are you on 2. Untracked (Unstaged) files 3. Staged files ---- ### Staging Area :::success OFTEN USED COMMAND ::: ```bash git add . ``` - `.` stands for everything - you are able to only add certain files ```bash git add NCU ``` ---- ### Staging Area :::success OFTEN USED COMMAND ::: ```bash git status ``` #### Any differents? ---- ## Quick Review After staging a file, what will you want to do? ---- ### Local Repos Which is `commit`. This means to put all the thing from stage into your repo, and telling what have you done or why do you do this. ---- #### Before that We need a **GOOD** convention of commit so that we know what you are writing ---- ### A COMMIT SHOULD ```shell <type>[optional scope]: <description> [optional body] [optional footer(s)] ``` - `type` -> need to discuss before using, however it often contians and can be more of them - `FIX` - `ADD` - `FEAT` - `DOCS` - `TEST` ---- ### A COMMIT SHOULD ```shell <type>[optional scope]: <description> [optional body] [optional footer(s)] ``` - `scope` -> sometimes we don't need them, but when we are in a big project, it will give a better view of what the error is - `description` -> the reason you make this commit - `body` -> further descriptions if needed - `footer` -> References ---- ### A COMMIT SHOULD NOT ![](https://i.imgur.com/DItz1Me.png) #### BE NONSENSE Trust me, you will find out that this is hard. ---- ### Let's try shell we? :::success OFTEN USED COMMAND ::: ```bash git commit ``` #### RESULT ```shell [master (root-commit) 6d13e9f] ADD: add NCU for demostrating how to commit. 1 file changed, 1 insertion(+) create mode 100644 NCU ``` ---- ### Let's see if it works :::success OFTEN USED COMMAND ::: ```bash git status ``` #### RESULT ```shell On branch master nothing to commit, working tree clean ``` ---- ### What if we have a typo? Go ahead and do something else to your file ```bash echo "Nobody Cares U" > NCU # This will overwrite `NCU` with content "Nobody Cares U" ``` ---- ### Let's check status again :::success OFTEN USED COMMAND ::: ```bash git status ``` #### RESULT ```shell On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: NCU no changes added to commit (use "git add" and/or "git commit -a") ``` ---- ### We just don't need that much descriptions ```bash git commit -m "FIX: typo of NCU" ``` --- ## Now we know how to create files to repo How to see the changes and what happens is the most important thing. ---- ### LOGS - `git log` -> repo's history - `git reflog` -> **whole** git history ---- ## Give it a try! ```bash git log ``` #### RESULT ```shell commit 9b605fe216228416f4b999f34c17d05f33f33ef1 Author: N0Ball <cwj0325@g.ncu.edu.tw> Date: Tue May 17 20:32:10 2022 +0000 FIX: typo of NCU commit 6d13e9f8e8deab9f1724a63e6ce1845548207a75 Author: N0Ball <cwj0325@g.ncu.edu.tw> Date: Tue May 17 20:23:41 2022 +0000 ADD: add NCU for demostrating how to commit. It's simply just a nonsense file with nonsense words; if it is for teaching it can be anything else. I suggest it to be a meme. ``` ---- ## Too long? ```bash git log --oneline ``` [More Usage](https://devhints.io/git-log) #### RESULT ```shell 9b605fe FIX: typo of NCU 6d13e9f ADD: add NCU for demostrating how to commit. ``` --- ## What if - You don't want the service down, but need the add modifications? - Or you have to cooperate with someone. ---- ## What if :::danger You will never ever put an unworkable program on master ::: #### Let's add pretend we are another user. ```bash git config user.name "jason" git config user.email "jason@g.ncu.edu.tw" ``` ---- ## SAVIOR - branches ![](https://i.imgur.com/BKcwVM9.png) ---- ## SAVIOR - branches :::success OFTEN USED COMMAND ::: ```bash git branch jason git branch dev ``` - `jason` -> your branch name - `dev` -> short of develope :::danger ALWAYS REMEMBER TO CHECK WHICH BRANCH YOU ARE ON ::: :::success OFTEN USED COMMAND ::: ```bash git status ``` ---- ## SAVIOR - branches List all the branches you have (**LOCAL**) :::success OFTEN USED COMMAND ::: ```bash git branch ``` #### RESULT ```shell dev jason * master ``` You can see that we have three branches. ---- ## SAVIOR - branches Switch through branches :::success OFTEN USED COMMAND ::: ```bash git checkout jason ``` - `jason` -> the target branch you want to switch to #### Result ```shell Switched to branch 'jason' ``` Remember to check if it is successed by `status` ---- ## Pretending someone Make more changes! ```bash echo "Nation Central University\!\!\!\!" >> NCU && echo "BAD" > AUTHOR # This appends "Nation Central University!!!!" to the file NCU and creates a file `AUTHOR` with content "BAD" ``` Append words to NCU is important for future usage. #### Don't forget to commit it! ---- ## Pretending someone :::success OFTEN USED COMMAND ::: ```bash git status ``` Have U done it right? ---- ## Quick review How to check your git movements? ---- ## REFLOG! ```bash git reflog ``` #### RESULT ```shell b50471b HEAD@{0}: commit: ADD: add comments to author 9b605fe HEAD@{1}: checkout: moving from master to jason 9b605fe HEAD@{2}: commit: FIX: typo of NCU 6d13e9f HEAD@{3}: commit (initial): ADD: add NCU for demostrating how to commit. ``` ---- ### Practice 1. change back to your name and email 2. make changes in your `dev` branch. 3. make changes in your `master` branch. 4. change to another person again. 5. make changes in `jason` branch. 6. Repeat `1.` once again. #### NOTE 1. **DO NOT** change anything from old files. 2. you can check your config by ```bash git config user.name git config user.email ``` ---- ## If you are correct ```bash git log --graph --all ``` - `graph` -> The graph view - `all` -> not only the current branch #### What are these :::info network ::: --- ## Time to add (`merge`) them together! ---- ## What is merge? Making two branches together. ![](https://i.imgur.com/BKcwVM9.png =500x300) ---- ## How to merge? you have to be on `master` branch! :::success OFTEN USED COMMAND ::: ```bash git merge jason ``` - `jason` -> your targeted branch #### Note branch `jason` will not change, that's reasonable, since you can only modify what's on your current branch. ---- ## If you are correct ```bash git log --graph --all ``` #### Wow Looks real cool ```bash git merge dev ``` Let's merge dev and see what happens! ---- ### With some prettfier ```shell * N0Ball -> Merge branch 'dev' (HEAD -> master) |\ | * N0Ball -> FIX: typo of filename (dev) | * N0Ball -> ADD: add readme file * | N0Ball -> Merge branch 'jason' |\ \ | * | jason -> FIX: modify author's comment to make it more readable (jason) | * | jason -> ADD: add comments to author | |/ * | N0Ball -> ADD: add something more to make the graph better * | N0Ball -> ADD: add something to make the log graph looks cool |/ * N0Ball -> FIX: typo of JASON * N0Ball -> ADD: add JASON for demostrating how to commit. ``` #### Try it yourself! ---- ## Merges are not always fluent 1. change to `dev` branch 2. modify `NCU` - remember that `jason` had append words to `NCU` - since it was merged to `master` -> `NCU` had appended words - both `dev` and `master` have its own appended words -> git doesn't know which to use -> **CONFLICT** ---- ## MERGE CONFLICTS :::success OFTEN USED COMMAND ::: ```bash git status ``` #### RESULT ```shell On branch master You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: JASON no changes added to commit (use "git add" and/or "git commit -a") ``` ---- ## MERGE CONFLICTS ```shell= FOREST SMELLS GOOD <<<<<<< HEAD National Central University!!!! ======= Very long president duration >>>>>>> dev ``` - `<<<<<< HEAD` -> current status - `>>>>>> dev` -> incomming changes You should choose. Keep both, leave one, delete both... whatever you like! #### I chose to keep dev ---- ## MERGE CONFLICTS 1. fix conflicts 2. stage changes 3. commit changes 4. **FINISH MERGE!** ---- ## If everything works fine ```bash * N0Ball -> Merge branch 'dev' ( (HEAD -> master)) |\ | * N0Ball -> ADD: add some words to JASON to make merge conflicts ( (dev)) * | N0Ball -> Merge branch 'dev' () |\| | * N0Ball -> FIX: typo of filename () | * N0Ball -> ADD: add readme file () * | N0Ball -> Merge branch 'jason' () |\ \ | * | jason -> FIX: modify author's comment to make it more readable ( (jason)) | * | jason -> ADD: add comments to author () | |/ * | N0Ball -> ADD: add something more to make the graph better () * | N0Ball -> ADD: add something to make the log graph looks cool () |/ * N0Ball -> FIX: typo of JASON () * N0Ball -> ADD: add JASON for demostrating how to commit. () ``` --- # GIT FLOW ---- ## How to git ![](https://i.imgur.com/f7gEjBn.png) ---- ## IMPORTANT :::danger You will never ever put an unworkable program on master. ::: - you should not modify anything on master. - you should be very aware of merging to master. ---- ## WHO? ```bash git blame AUTHOR ``` - `AUTHOR` -> the target file to ask #### Expected result ```shell 3add7ab5 (jason 2022-05-17 21:47:52 +0000 1) YOU ARE BAD ``` - `-L a, b` can be used for lines --- ## OOPS ---- ## I don't like this ---- ## Quick Reviews `STAGES` of git ---- ## Quick Review - Working Directory - Staging Area - Repo ---- ## How to get to the wanted version? ---- ## I don't like Working Directory :::success OFTEN USED COMMAND ::: ```bash git checkout . ``` - same as `add`, `.` for everything or you can type the filename you want to restore ---- ## QUICK TEST ```bash echo "OUO" > test ``` ```bash cat test # prints out the content inside test ``` ```bash git checkout test ``` ```bash cat test ``` ---- ## I don't like Staging Area ```bash git restore --staged . ``` - same as `add`, `.` for everything or you can type the filename you want to restore ---- ## QUICK TEST ```bash echo "OUO" > test git add . ``` ```bash git status ``` ```bash git restore --staged test ``` ```bash git status ``` ---- ## I don't like REPO ```bash git reset ``` #### OPTIONS 1. `--soft` -> only changing status 2. `--hard` -> changes everything back to the commit status - Just like `git reset --soft` + `git checkout .` ---- ## QUICK TEST SOFT ```bash echo "wrong commit" > test git add . git commit -m "OOPS: wrong commit" ``` ```bash git log cat test ``` ```bash echo "right commit" > test git reset --soft xxxxx ``` - xxxxx is the commit id ```bash git log cat test git status ``` ---- ## QUICK TEST HARD ```bash echo "original commit" > test git add . git commit -m "OOPS: wrong commit" ``` ```bash git log && cat test ``` ```bash echo "new commit" > test git reset --hard xxxxx ``` - xxxxx is the commit id ```bash git log && cat test git status ``` ---- ## I don't like COMMIT ```bash git commit --amend ``` ---- ## QUICK TEST ```bash echo "test" > test git add . git commit -m "ADD: discription of T3ST" ``` ```bash git log ``` ```bash git commit --amend -m "ADD: description for TEST" ``` ```bash git log ``` --- # REMOTE ---- ## LET'S REMOTE ---- ## REGISTRATION [register a gitlab account!](https://gitlab.dos.phy.ncu.edu.tw/users/sign_up) ---- ## GET REMOTE REPO :::success OFTEN USED COMMAND ::: `git clone <repo url>` --- # GITHUB --- ## WHAT IS > At a high level, GitHub is a website and cloud-based service that helps developers store and manage their code, as well as track and control changes to their code. [name=https://kinsta.com/application-hosting/] ---- Clone methods - HTTPS: ask for username and password - SSH: use ssh key, which doesn't require username and password ---- [Create a github](https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F&source=header-home) ![](https://i.imgur.com/X71yDYE.png) --- ## Lets create a repository ---- Go to Create a new repository ![](https://i.imgur.com/J5Dy5dZ.png) ---- fill out the forms ![](https://i.imgur.com/cH2lepd.png) ---- You made it! ![](https://i.imgur.com/NrOJGCq.png)

    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