Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git remove file from stash

People also ask

How do I remove a file from a git stash?

git restore --staged path/to/file. git reset HEAD -- path/to/file to remove the file from the staging area.

How do I get rid of stashed changes to a file?

Go to Source Control tab. Check the STASHES section. You will find all your stashes (same like git stash list ) You will find direct buttons to Apply Stash, Compare with HEAD and Delete Stash respectively for each stash.

How do I remove a file from git?

The git rm command can be used to remove individual files or a collection of files. The primary function of git rm is to remove tracked files from the Git index. Additionally, git rm can be used to remove files from both the staging index and the working directory.

Does git clean remove stash?

A safer option is to run git stash --all to remove everything but save it in a stash. Assuming you do want to remove cruft files or clean your working directory, you can do so with git clean .


A stash is a commit (or really, two or even sometimes three commits) and you cannot change a commit. The literal answer to your question, then, is "you can't". Fortunately, you don't need to.

You say you can't apply your stash because of a conflicting file. But you can apply it, you just get a merge conflict. All you need to do is resolve the merge conflict.

Let's say the conflict is in file README.txt, just so there's something to write about here.

If you want to resolve it by keeping the on-branch version, apply the stash, then check out the on-branch version to resolve the conflict:

git stash apply
git checkout --ours -- README.txt  # or git checkout HEAD -- README.txt

If you want to keep the in-stash version, extract that one:

git checkout --theirs -- README.txt # or git checkout stash -- README.txt

Or, use any old merge resolution tool (I just use a text editor), and then "git add" the result.

Once you are all done with the stash, git stash drop will "forget" the commits that make up the stash. (Don't do this until you are sure you are done with it; it's very hard to get it back afterward.)


There is a workaround for this situation:

  1. save your stash as a patch file:

    $ git stash show -p > stash.patch
    
  2. apply this patch, skipping the conflicts (you will be asked for resolution of conflicts, just skip missing files):

    $ patch -p1 < stash.patch
    

Don't forget to clean up stash.patch afterwards!


  1. Stash your uncommitted changes.
  2. Apply your original stash
  3. Discard the file
  4. 4 Apply the stash containing your uncommitted changes.