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.7 git reset 回到上一步, git tag tags: Git, 5x --- 7.7 0504 git reset 回到上一步; git tag 標籤 === # `git reset` + `index` ![commit記錄](https://i.imgur.com/Z3z98rQ.png) 若此時我們想回到`master`分支上前一個commit的狀態: `git reset 85e7e30` 1. 目前的分支以及HEAD移動到上一次commit 2. Commit`e12d8ef`暫時看不見了 (而不是砍掉) 3. 原本Commit的內容,會被放至工作目錄(預設行為) # `git reset` `--參數` 決定檔案去留 `-- hard` 工作目錄和暫存區的內容都丟掉(直接丟掉) `-- soft` 工作目錄和暫存區的內容都不變(檔案丟回暫存區) `(預設)` `--mixed` 工作目錄不變,暫存區內容丟掉(檔案丟回工作目錄) ## hard `-- hard`工作目錄和暫存區的內容都丟掉(直接丟掉) 指令: `git reset5 85e7e30 --hard` ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git reset 85e7e30 --hard HEAD is now at 85e7e30 add hello tingdeAir:git-branch1 tingtinghsu$ git log --oneline 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git status On branch master nothing to commit, working directory clean ``` ### 重點1. 復原`--hard`裡被丟掉的工作目錄和暫存區內容 #### A. 絕對定位 (1) command line 指令: `git reset e12d8ef --hard` 原本的最後一次commit: `e12d8ef` 意義: 1. 目前的分支以及HEAD移動到C5 (最後一次的commit) 2. 整個專案變成C5時候的樣子 (所有commit的資料都回來了) ```bash tingdeAir:git-branch1 tingtinghsu$ git reset e12d8ef --hard HEAD is now at e12d8ef add database.yml in config folder e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit ```` (2) GUI軟體: source tree 在想要復原的commit上按右鍵 -> `Reset current branch to this commit` -> `Using mode:` 1. Mixed - keep working copy but reset index 2. Soft - keep all local changes 3. Hard - discard all working copy changes #### B. 相對定位 想回到某個commit的上一個、上兩個commit `^` = Caret (卡瑞特) `~` = Tilde (提爾達) * `^` Caret ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git reset e12d8ef^ tingdeAir:git-branch1 tingtinghsu$ git log --oneline 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git reset 85e7e30^^ Unstaged changes after reset: M index.html tingdeAir:git-branch1 tingtinghsu$ git status On branch master 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 Untracked files: (use "git add <file>..." to include in what will be committed) config/ hello.html ``` * `~` Tilde 用HEAD當代名詞 `git reset HEAD~2` : 我想要變成HEAD的前2個狀態! ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git reset HEAD~2 tingdeAir:git-branch1 tingtinghsu$ git log --oneline 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit ``` ### 重點2. 查詢不見的commit: `git reflog` reflog = reference log 列出HEAD移動的軌跡圖 ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git reset HEAD~2 tingdeAir:git-branch1 tingtinghsu$ git log --oneline 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit ``` ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git status On branch master nothing to commit, working directory clean tingdeAir:git-branch1 tingtinghsu$ git reset 85e7e30 tingdeAir:git-branch1 tingtinghsu$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) config/ tingdeAir:git-branch1 tingtinghsu$ git reflog 85e7e30 HEAD@{0}: reset: moving to 85e7e30 e12d8ef HEAD@{1}: reset: moving to e12d8ef 657fce7 HEAD@{2}: reset: moving to 657fce7 85e7e30 HEAD@{3}: reset: moving to 85e7e30 /*回到原來的狀態*/ tingdeAir:git-branch1 tingtinghsu$ git reset e12d8ef --hard HEAD is now at e12d8ef add database.yml in config folder tingdeAir:git-branch1 tingtinghsu$ git status On branch master nothing to commit, working directory clean tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit ``` ## soft `-- soft` 工作目錄和暫存區的內容都不變(檔案丟回暫存區) ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git reset 657fce7 --soft tingdeAir:git-branch1 tingtinghsu$ git log --oneline 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git status On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) new file: hello.html ``` ## mixed (預設) `--mixed` 工作目錄不變,暫存區內容丟掉(檔案丟回工作目錄) ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git status On branch master nothing to commit, working directory clean tingdeAir:git-branch1 tingtinghsu$ git reset 85e7e30 tingdeAir:git-branch1 tingtinghsu$ git status On branch master Untracked files: (use "git add <file>..." to include in what will be committed) config/ ``` # reset和checkout的差異 checkout: 去其他的commit看看 1. 分支不動,HEAD移動到C3 2. 專案變成C3時候的狀態(如果原本是乾淨狀態的話) 3. checkout不像reset指令有相關參數可以設定檔案去留 ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git checkout 657fce7 Note: checking out '657fce7'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at 657fce7... add container tingdeAir:git-branch1 tingtinghsu$ git log --oneline 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit ``` # `git tag` + `版本號` Q: 為什麼要用標籤? A: 不想要記得一長串文數字 # tag的使用情境 里程碑 (產品更新上線) `git tag 1.0.0 cef6e40` ![在commit上設定tag](https://i.imgur.com/9Yrmwaq.png) ```bash tingdeAir:git-branch1 tingtinghsu$ git log --oneline e12d8ef add database.yml in config folder 85e7e30 add hello 657fce7 add container abb4f43 update index page cef6e40 create index page cc797cd init commit tingdeAir:git-branch1 tingtinghsu$ git tag 1.0.0 cef6e40 ``` # tag 用於 `git reset` ```bash tingdeAir:git-branch1 tingtinghsu$ git reset 1.0.0 --hard HEAD is now at cef6e40 create index page tingdeAir:git-branch1 tingtinghsu$ git log --oneline cef6e40 create index page cc797cd init commit ``` # tag 用於 `git checkout` ```bash tingdeAir:git-branch1 tingtinghsu$ git checkout 1.0.0 Note: checking out '1.0.0'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at cef6e40... create index page tingdeAir:git-branch1 tingtinghsu$ git branch * (HEAD detached at 1.0.0) master tingdeAir: ``` # tag 和 branch 的差異 標籤和分支有什麼不同 1. tag 標籤貼上去之後就停在同一點 2. branch 分支會跟著commit的推進而延伸長大 > 留下來(tag),或我跟你走(branch)!

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