2016-09-26 18:49:39 +01:00
|
|
|
# git reset
|
|
|
|
|
|
|
|
> Undo commits or unstage changes, by resetting the current git HEAD to the specified state.
|
2016-10-27 18:27:41 +01:00
|
|
|
> If a path is passed, it works as "unstage"; if a commit hash or branch is passed, it works as "uncommit".
|
2016-09-26 18:49:39 +01:00
|
|
|
|
2016-10-27 18:27:41 +01:00
|
|
|
- Unstage everything:
|
2016-09-26 18:49:39 +01:00
|
|
|
|
2016-10-27 18:27:41 +01:00
|
|
|
`git reset`
|
2016-09-26 18:49:39 +01:00
|
|
|
|
2016-10-27 18:27:41 +01:00
|
|
|
- Unstage specific file(s):
|
2016-09-26 18:49:39 +01:00
|
|
|
|
2016-10-27 18:27:41 +01:00
|
|
|
`git reset {{path/to/file(s)}}`
|
|
|
|
|
|
|
|
- Unstage portions of a file:
|
|
|
|
|
|
|
|
`git reset -p {{path/to/file}}`
|
|
|
|
|
|
|
|
- Undo the last commit, keeping its changes (and any further uncommitted changes) in the filesystem:
|
|
|
|
|
|
|
|
`git reset HEAD~`
|
|
|
|
|
|
|
|
- Undo the last two commits, adding their changes to the index, i.e. staged for commit:
|
|
|
|
|
|
|
|
`git reset --soft HEAD~2`
|
|
|
|
|
|
|
|
- Reset the repository to a given commit, discarding committed, staged and uncommitted changes since then:
|
|
|
|
|
|
|
|
`git reset --hard {{commit}}`
|