Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Atlas7/240255faeb19d4177715 to your computer and use it in GitHub Desktop.
Save Atlas7/240255faeb19d4177715 to your computer and use it in GitHub Desktop.
Git - Stash only one file out of multiple files that have changed with Git?

Say I have 5 files: (file1, file2, ... file5).

All have been commited.

Say now all 5 files have been changed.

When you issue git status, all 5 files should be shown as (red) unstaged status.

Say I am happy with the changes in file1 to file4, but not file5 (i.e. I'd like to revert file5 to the last committed stage).

To do this:

Stage all 5 files

git add .

Unstaged file5

git reset file5

Stage file5

git stash --keep-index

Now, file5 is back to original commited stage.

References:

Stackoverflow forum - Stash only one file out of multiple files that have changed with Git

@nhuzaa
Copy link

nhuzaa commented Feb 20, 2018

Worked Perfectly Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment