2016-09-26 18:49:39 +01:00
|
|
|
# git reset
|
|
|
|
|
2021-01-07 14:06:38 +00:00
|
|
|
> 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".
|
2019-06-03 01:06:36 +01:00
|
|
|
> More information: <https://git-scm.com/docs/git-reset>.
|
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
|
|
|
|
2022-12-06 06:47:56 +00:00
|
|
|
`git reset {{path/to/file1 path/to/file2 ...}}`
|
2016-10-27 18:27:41 +01:00
|
|
|
|
2021-05-28 12:30:39 +01:00
|
|
|
- Interactively unstage portions of a file:
|
2016-10-27 18:27:41 +01:00
|
|
|
|
2021-05-28 12:30:39 +01:00
|
|
|
`git reset --patch {{path/to/file}}`
|
2016-10-27 18:27:41 +01:00
|
|
|
|
|
|
|
- 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`
|
|
|
|
|
2017-05-15 17:45:43 +01:00
|
|
|
- Discard any uncommitted changes, staged or not (for only unstaged changes, use `git checkout`):
|
|
|
|
|
|
|
|
`git reset --hard`
|
|
|
|
|
2016-10-27 18:27:41 +01:00
|
|
|
- Reset the repository to a given commit, discarding committed, staged and uncommitted changes since then:
|
|
|
|
|
|
|
|
`git reset --hard {{commit}}`
|