Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

git - 您如何存储未跟踪的文件?(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.

(我对一个文件进行了更改,再加上一个新文件,并希望在我切换到另一个任务时使用git stash进行保存。)

But git stash by itself stashes only the changes to the existing file;

(但是git stash本身仅存储对现有文件的更改;)

the new file remains in my working tree, cluttering up my future work.

(新文件保留在我的工作树中,使以后的工作变得混乱。)

How do I stash this untracked file?

(我如何隐藏这个未跟踪的文件?)

  ask by skiphoppy translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To stash your working directory including untracked files (especially those that are in the .gitignore) then you probably want to use this cmd:

(要存储您的工作目录,包括未跟踪的文件(尤其是.gitignore中的文件),则可能要使用此cmd:)

git stash --include-untracked

More details: (更多细节:)

Update 17 May 2018:

(2018年5月17日更新:)

New versions of git now have git stash --all which stashes all files, including untracked and ignored files.

(新版本的git现在具有git stash --all stash-全部隐藏所有文件,包括未跟踪和忽略的文件。)
git stash --include-untracked no longer touches ignored files (tested on git 2.16.2).

(git stash --include-untracked不再接触忽略的文件(在git 2.16.2上测试)。)

Original answer below:

(原始答案如下:)

Warning, doing this will permanently delete your files if you have any directory/* entries in your gitignore file.

(警告,如果您在gitignore文件中有任何目录/ *条目,这样做将永久删除您的文件。)

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.

(从1.7.7版本开始,您可以使用git stash --include-untrackedgit stash save -u来存储未跟踪的文件而不进行暂存。)

Add ( git add ) the file and start tracking it.

(添加( git add )文件并开始跟踪它。)

Then stash.

(然后藏起来。)

Since the entire contents of the file are new, they will be stashed, and you can manipulate it as necessary.

(由于文件的全部内容都是新内容,因此将其隐藏起来,您可以根据需要进行操作。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...