Search code examples
gitgit-stash

How better to restore modified files after git stash?


Making git pull I got errors :

error: Your local changes to the following files would be overwritten by merge:
        public/js/file.js
        public/file.json
Please commit your changes or stash them before you merge.

I saved list of all modified files with

git status

and command run

git stash

I merged all files now I need to restore all my changes. List of all files is rather big, including deleting/new files, like:

On branch main
Your branch is up to date with 'origin/main'.

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

        deleted:    app/Http/Controllers/ItemController.php
        new file:   app/Http/Controllers/BoxController.php
        
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   .gitignore
        modified:   app/Http/Controllers/ItemController.php
        
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        app/Http/Controllers/ItemController.php
        app/Http/Requests/ItemRequest.php

When I need to restore some modified files I can apply changes manually, but

  1. How to restore deleted/new files?

  2. Is the listing of all modified files is rather big, how can I make it better, not manually checking them one by one?


Solution

  • To restore your changes do git stash apply. However, it looks like your merge is incomplete. You need to git commit the merge before trying to apply your stash.