Search code examples
gitstaging

how to get a file from the staging area?


I have a file "a.txt" I do

git add a.txt

Now, I remove a.txt (or modify it).

Then I want that a.txt that I have added to the staging area

How do I do that?


Solution

  • The output of git status has the info you're looking for:

    # 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)
    

    So, in this instance, you should run:

    git checkout -- a.txt