Can you set the order in which files appear on "git" commands?

I want to stash a single file. Since git stash does not allow a filename as a parameter, I have to use git stash -p and select the file among the rest of changes.

This works fine if changes not staged for commit do not include many files, or if the file I want to stash is one of the first ones.

However, if there are many files and the one I want to stash is to the end of the list, I have to go through all the other ones until I get to the desired one. And this is a bit tedious.

So I was wondering: is there a way to define the order in which the files not staged for commit appear upon doing git stash -p ?


You could do this:

git add file
git stash -k -u
git stash
git stash pop stash@{1}
git checkout file

It's totally a hack, and it will work only if you don't have staged changes before doing this, but as far as I know there is no good way to do what you need.

First, we add file to the index, then we stash everything else ( -k to keep file in the index and -u to also take untracked files), then stash file . The last two commands are cleanup: we apply the first stash to retrieve everything, then checkout file to remove its changes (as stash does). In the end, you should have your stash with only your changes on file in it and your directory unchanged except for file which is back to the HEAD revision.

链接地址: http://www.djcxy.com/p/24520.html

上一篇: 为什么JavaScript在迭代时将数组索引转换为字符串?

下一篇: 你能设置文件出现在“git”命令上的顺序吗?