markdown Git note

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Git note相关的知识,希望对你有一定的参考价值。

## I did something terribly wrong, please tell me git has a magic time machine!?!
git reflog

```
# you will see a list of every thing you've done in git, across all branches!
# each one has an index HEAD@{index}
# find the one before you broke everything
git reset HEAD@{index}
# magic time machine
```
## I committed and immediately realized I need to make one small change!

````
# make your change
git add . # or add individual files
git commit --amend
# follow prompts to change or keep the commit message
# now your last commit contains that change!
```

## Oh shit, I need to change the message on my last commit!

````
git commit --amend
# follow prompts to change the commit message
````

## I accidentally committed something to master that should have been on a brand new branch!

````
# create a new branch from the current state of master
git branch some-new-branch-name
# remove the commit from the master branch
git reset HEAD~ --hard
git checkout some-new-branch-name
# your commit lives in this branch now :)
````

## I accidentally committed to the wrong branch!

````
# undo the last commit, but leave the changes available
git reset HEAD~ --soft
git stash
# move to the correct branch
git checkout name-of-the-correct-branch
git stash pop
git add . # or add individual files
git commit -m "your message here"
# now your changes are on the correct branch
````

以上是关于markdown Git note的主要内容,如果未能解决你的问题,请参考以下文章

markdown Oracle Notes

markdown PHPExcel Notes和代码片段

markdown [注意:HTML] #notes #html

markdown SEO调整note.md

markdown elixir_note.md

markdown _notes.md