Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep stash after git filter-branch --subdirectory-filter

Tags:

git

git-stash

I recently split out my repository (residing in bigproj) using git filter-branch --subdirectory-filter deep/in/my/project. Then, I moved .git directory to deep/in/my/project.

Now, stash is in a strange state, where the top stash is something like:

stash@{0}: filter-branch: rewrite

I can't drop this stash, as I get this error (after git stash drop):

refs/stash@{0}: not a valid stashed state

Now, even if I know the refid of stash@{1}, it still contains diffs for files in bigproj hierarchy. Is it possible to re-write stash data, so that it only contains files belonging to deep/in/my/project hierarchy?

like image 792
Nikola Knezevic Avatar asked Aug 12 '11 12:08

Nikola Knezevic


People also ask

Does git stash persist across branches?

In its simplest form, the git stash command creates a stash entry. To reapply our stashed changes at a later point, we can use git stash apply . We can apply the stash entry to a different branch – it doesn't have to be the branch that we created the stash from.

What is the purpose of git filter branch `?

git-filter-branch can be used to get rid of a subset of files, usually with some combination of --index-filter and --subdirectory-filter .

Does git stash affect remote branch?

Git stash saves the uncommitted changes locally, allowing you to make changes, switch branches, and perform other Git operations. You can then reapply the stashed changes when you need them. A stash is locally scoped and is not pushed to the remote by git push .

Can you stash a specific file?

To stash a specific file, use the “git stash push” command and specify the file you want to stash. However, the other tracked files that may be modified in your current working directory are untouched.


1 Answers

I had the same problem after using git filter-branch. The following command prunes the stash completely and therefore also deletes the entries created by git filter-branch. Warning! that all stashed changes may be impossible to recover after calling this command, so make sure to apply all other stashed states before you call the command.

    git stash clear
like image 188
Tones29 Avatar answered Oct 21 '22 04:10

Tones29