Search code examples
gitstagegit-indexgit-stage

how to remove untrack changes but keeping indexed changes


in my git status I see this

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

modified: file1
modified: file2
modified: file4

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

modified: file1
modified: file4

how can I reset the files to the current staged changes and discarding only the non-staged changes.


Solution

  • You can do it using checkout command, just like that:

    git checkout file1
    git checkout file4
    

    Hope this help