Search code examples
gitgit-stash

Applying stash changes in git, where the stash contains files that has been moved


My current branch has moved certain files to different folders, and the stash created had made changes to the files which were located in the old folders. How to properly apply the stash without breaking anything, and would like to know the easiest method for this.


Solution

  • I see a few simple steps to do:

    1. Move some files, only those that are required by a git stash show, back to old place:

      git mv file old_place/file
      
    2. Apply stash to those files:

      git stash pop
      
    3. Merge the changes, if any:

      vim ...
      git add ...
      
    4. Move files back to the proper places:

      git mv old_place/file file
      

    After that you will get the added into index files with applied stash.