首页 > 解决方案 > Resetting a new file in staging area to working directory in Git

问题描述

In Git I have checked out a new branch branch band made multiple changes including edits, new files, folders etc. I need to revert back to an old branch branch a to make changes, so I want to stash all changes made in branch b. However I have some untracked files and folder in branch b so if I revert back to branch a, they follow as untracked files.

I attempted to add and then reset these untracked files with the intention of them moving to the working directory, but they revertedback to an untracked file (no surprise).

Question

How do I add these untracked files in branch b to the working directory ready to be stashed? (without committing)

标签: git

解决方案


您可能有兴趣使用

git add --intend-to-add

开始跟踪文件而不真正添加/提交它们。

从手册:

-N, --intent-to-add

仅记录稍后将添加路径的事实。路径的条目被放置在没有内容的索引中。除其他外,这对于使用 git diff 显示此类文件的未暂存内容并使用 git commit -a 提交它们很有用。


推荐阅读