Search code examples
gitundo

How to revert/reset/undo a locally modified file to a previously staged but not committed state?


I changed a file, then did git add it, and then made more changes. Then realized that the staged changes were OK, but the most recent ones weren't. Since I didn't commit yet there is no branch to checkout. So how do I revert/reset/undo the edits up to the staged state?


Solution

    1. change a file.
    2. git add without commit
    3. change the file again.

    use "git restore " to revert to status after step2