How do you stash an untracked file?
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?
Warning, doing this will permanently delete your files if you have any directory/* entries in your gitignore file.
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. Since the entire contents of the file are new, they will be stashed, and you can manipulate it as necessary.
As of git 1.7.7, git stash
accepts the --include-untracked
option (or short-hand -u
). To include untracked files in your stash, use either of the following commands:
git stash --include-untracked
git stash -u
Warning, doing this will permanently delete your files if you have any directory/* entries in your gitignore file.
Add the file to the index:
git add path/to/untracked-file
git stash
The entire contents of the index, plus any unstaged changes to existing files, will all make it into the stash.
链接地址: http://www.djcxy.com/p/9822.html上一篇: git重置后留下未更新的更改
下一篇: 你如何隐藏未跟踪的文件?