+8 votes
1 view
in Devops and Agile by (28.1k points)
edited by

I have changes to a file, plus a new file, and would like to use git stash to put them away while I switch to another task. But git stash by itself stashes only the changes to the existing file; the new file remains in my working tree, cluttering up my future work. How do I stash this untracked file?

2 Answers

+8 votes
by (48k points)

For this query, there is an update in git so for

New versions of git now have 

git stash --all 

which stashes all files, including untracked and ignored files.

git stash --include-untracked 

no longer touches ignored files.

As of version 1.7.7, you can use

git stash --include-untracked 

or 

git stash save -u 

to stash untracked files without staging them.

Add (git add) the file and start tracking it. Then stash. But with the update, this is no longer exists.

Reference: https://git-scm.com/docs/git-stash

+9 votes
by (63.4k points)

I used

git stash 

for stashing the modified .gitIgnore file.

For stashing .classpath and .project file, I used

git stash --include-untracked

and it removed the files from my local repository. Absence of these files takes away my capability of working on my work location in eclipse. So, I proceeded on with completing the procedure for pushing the committed files to a remote location. Once I have pushed the committed files successfully, I used

git stash pop

This pasted the same files back in my workspace. This gave back to me my ability to work on the same project in eclipse. Hope this helps you!

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...