tldr/pages/common/git-reset.md

34 lines
964 B
Markdown
Raw Normal View History

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.
> If a path is passed, it works as "unstage"; if a commit hash or branch is passed, it works as "uncommit".
> More information: <https://git-scm.com/docs/git-reset>.
2016-09-26 18:49:39 +01:00
- Unstage everything:
2016-09-26 18:49:39 +01:00
`git reset`
2016-09-26 18:49:39 +01:00
- Unstage specific file(s):
2016-09-26 18:49:39 +01:00
`git reset {{path/to/file1 path/to/file2 ...}}`
- Interactively unstage portions of a file:
`git reset --patch {{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`
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`
- Reset the repository to a given commit, discarding committed, staged and uncommitted changes since then:
`git reset --hard {{commit}}`