tingtinghsu
    • 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
      • Invitee
    • 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
    • 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 Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync 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
Invitee
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
--- title: Git 7.4 小劇場 part3 tags: Git, 5x --- 7.4 0515 Git 小劇場 Part 3 === # Case 1 `git add .`完之後準備要commit,卻發現忘記開分支 解法 1. 在此分支加上新貼紙`fish`,`git branch fish`,並且趕快`git checkout fish`過去。 2. 再進行一次`git add .`,`git commit` 3. 在`fish`分支上,刪掉`master branch`(撕掉貼紙) ``` tingdeAir:git-rebase tingtinghsu$ touch fish1.html tingdeAir:git-rebase tingtinghsu$ git add . tingdeAir:git-rebase tingtinghsu$ git branch fish tingdeAir:git-rebase tingtinghsu$ git checkout fish tingdeAir:git-rebase tingtinghsu$ git add . tingdeAir:git-rebase tingtinghsu$ git commit -m "add fish1" [fish 7ae141a] add fish1 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 fish1.html tingdeAir:git-rebase tingtinghsu$ git branch -d master ``` 4. 回到前一狀態(尚未增加新檔案的狀態),再度加上`master branch`(再貼上master貼紙) # Case 2 比較機密的檔案不想放在Git裡 解法: ignore https://github.com/github/gitignore 1.新增`.gitignore` ``` MacBook-Air:git-rebase tingtinghsu$ touch .gitignore ``` 2.編輯`.gitignore`,加入黑名單 ```bash pig* bird* ``` 3. 加入黑名單的檔案不再進入版控中 ``` MacBook-Air:git-rebase tingtinghsu$ touch pig.html MacBook-Air:git-rebase tingtinghsu$ touch bird.html MacBook-Air:git-rebase tingtinghsu$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) .gitignore ``` 限制: 之前已經產生的檔案,就算加入了`.gitignore`,還是會被git記錄到。必須先刪除再重新產生一份同名檔案。 # Case 3 手邊的事情做一半,被老闆叫去修別的bug: `git stash` 可能的解法: 切換到master分支,做完再切回來 ``` git commit git checkout master ...(做別的步驟) git checkout cat git reset HEAD^ --mix ``` 更好的解法: 1. `git stash` 使用git 中斷指令 (也是一種commit,只是不會出現在歷史紀錄上) ``` tingdeAir:git-stash tingtinghsu$ git stash Saved working directory and index state WIP on cat: e12d8ef add database.yml in config folder HEAD is now at e12d8ef add database.yml in config folder ``` 2. `git stash list` 查詢中斷的項目 ``` tingdeAir:git-stash tingtinghsu$ git stash list stash@{0}: WIP on cat: e12d8ef add database.yml in config folder ``` 3. 切換到master分支修改完bug,再切回自己手邊待做的branch ``` tingdeAir:git-stash tingtinghsu$ git checkout master Switched to branch 'master' ...(做別的步驟) tingdeAir:git-stash tingtinghsu$ git checkout cat Switched to branch 'cat' ``` 4. `git stash pop` ``` tingdeAir:git-stash tingtinghsu$ git stash pop On branch cat Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: index.html no changes added to commit (use "git add" and/or "git commit -a") Dropped refs/stash@{0} (3e7ae10f684ba63b95b38ff8697cbd06f8c7179b) ``` 重新回到之前的進度。 重點: `git stash apply` 或`git stash pop`兩者都可以使用,但`pop`指令會把原本的stash砍掉,`apply`保留stash ``` Switched to branch 'master' tingdeAir:git-stash tingtinghsu$ git checkout cat Switched to branch 'cat' tingdeAir:git-stash tingtinghsu$ git stash apply On branch cat Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: index.html no changes added to commit (use "git add" and/or "git commit -a") tingdeAir:git-stash tingtinghsu$ git stash list stash@{0}: WIP on cat: e12d8ef add database.yml in config folder ``` # Case 4. 線上專案已被其他人執行`git push -f` 只能找最接近歷史的一次記錄再`git push -f`蓋回去,然後修改中間改變過的檔案 # Case 5. 已經push出去的進度該如何reset? eg. 多人協作的情況下:想取消上次版本的其中一個commit 解法: 使用`reverse commit` 1. 在source tree想要取消的那顆commit上按右鍵`reverse commit` 2. `reverse commit`會做出新的commit,逆轉上次做的步驟(如果上次commit是新增檔案,這次commit就是刪除檔案) eg. 如果是只有自己一個人的專案,直接reset,commit再`git push -f`就好

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