- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
当暂存已删除或重命名的文件,然后取消暂存它们时,它们将恢复为已删除和未删除状态。
在下面的例子中状态:
$ git status s
A file0
D file1
R file2 -> file3
?? file4
运行 git stash push -k -u
然后 git stash pop --index
将使我处于以下状态:
$ git status s
A file0
D file1
R file2 -> file3
?? file1
?? file2
?? file4
我希望以原始状态结束,删除的文件不会在 pop
之后重新显示为未跟踪。
有什么办法解决这个问题吗?
编辑:这是一个重现问题的脚本(在 Mac OS X 10.13.2 和 git 2.16.1 上测试)
#!/usr/bin/env bash
echo -e "\nInitializing a fresh git dir..."
mkdir gitStashIssue && cd $_
rm -rf * .*
git init
echo -e "\nPreparing git state for test..."
# Create files and commit them
echo 'abc' > file1
echo 'aabbcc' > file2
echo 'aaabbbccc' > file3
echo 'aaaabbbbcccc' > file4
git add .
git commit -m 'initial commit'
# Make changes and add them to stage
echo `cat file1` >> file1
echo `cat file2` >> file2
git add .
# Make another change to a staged file without
# staging it, making it partially staged
echo `cat file1` >> file1
# Delete and rename files
git rm file3
git mv file4 fileRenamed
# Add untracked file
echo "untracked" > untrackedFile
# git status -s should now show
# MM file1
# M file2
# D file3
# R file4 -> fileREnamed
# ?? untrackedFile
echo -e "\nCurrent git status is:"
git status -s
echo -e "\nStasing changes..."
git stash save -u -k
# git status -s should now show
# M file1
# M file2
# D file3
# R file4 -> fileREnamed
# ?? file3
# ?? file4
echo -e "\ngit status after stashing files is:"
git status -s
echo -e "\ncleaning up deleted and renamed files..."
git clean ./ -f
echo -e "\ngit status after cleanup:"
git status -s
echo -e "\nCommiting unstashed changes..."
git commit -m 'commit unstashed changes'
# This causes a conflict in file1
# git status -s should now show
# UU file1
# ?? untrackedFile
git stash pop --index
echo -e "\ngit status after unstashing:"
git status -s
最佳答案
记住:git 不跟踪文件重命名。它跟踪文件内容。
当索引包含对具有相同内容的不同文件的删除和创建时,git 的重命名检测将(可能)断定这是重命名,并有助于将其显示为重命名。不过,这实际上并没有改变索引中的内容。 “真正”发生的确实是先删除后创建,git 只是试图更有帮助地显示它。
自己试试:
$ cp file1 boink
$ rm file1
$ git add .
$ git status
效果相同:
$ git mv file1 boink
$ git status
此重命名检测仅适用于已添加到索引中的内容。现在执行 git reset
你就会明白我的意思了:
$ git reset
$ git status
Changes not staged for commit:
deleted: file1
Untracked files:
boink
我们可以使用 git 命令 git ls-files
列出索引中存在的文件。实际上,这些是 git 目前认为存在的文件。当我们像上面那样重命名时,输出是:
# git ls-files
boink
file2
file3
file4
就索引而言,file1已经不存在了。我们删除了它,然后我们创建了 boink
。 git status
很友好,它向我们展示了重命名检测的结果,但请记住,索引并不关心这些。
现在我们运行 git stash -k -u
。 -k
告诉 stash 不要触及索引,所以它不会。考虑一下 stash
联机帮助页的第一段:
Use git stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory. The command saves your local modifications away and reverts the working directory to match the HEAD commit.
因此:我们要求 stash 保存我们的本地修改(不触及索引),并恢复工作目录以匹配 HEAD 提交。file1
存在于 HEAD 提交中,所以它回来了。但是 file1
不再在索引中,因为我们删除了它。因此,file1
现在是一个未跟踪的文件。由于我们没有触及索引,因此新文件 boink
和它是 file1
重命名结果的记录保留在索引中。因此,您可以从 git status
获得可能令人惊讶的输出:
Changes to be committed:
renamed: file1 -> boink
Untracked files:
file1
关于git stash 恢复已删除和重命名文件的索引状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48446845/
我如何在一个语句中删除最旧的存储(比如最旧的 5 个存储)而不是像这样做: git stash drop stash@{3} git stash drop stash@{4} git stash dr
我认为它们应该基本相同,但是当我尝试 $ git stash show -p stash@{N} 和 $ git show stash@{N} 后者显示了一些额外的提交信息,但实际差异要短得多。 (前
我一直在 git 的一个分支上工作,然后我藏了一些东西。在分支之间进行一些切换后,我回到了我的初始分支,进行了一些新的更改,将它们存储起来,然后意识到我想回到我第一次存储之前所做的更改。 所以我的问题
我使用 git 管理主目录中的配置文件。这是我的主目录中 .gitignore 文件的简化内容。 * !.bashrc !.bash_aliases !.gitignore 我在我的主目录 .bash
这个问题在这里已经有了答案: How to remove range of git stash? (6 个答案) 关闭 4 年前。 我有以下存储列表(git stash list): stash@{
我正在尝试使用以下方式应用特定的存储: git stash apply stash@{2} 但最终出现这个错误: fatal: ambiguous argument 'stash@': unknown
我想创建一个 git 包,它只包含我的存储中不在存储所基于的点的提交。我想这样做而不是发送每一次提交,因为我知道收件人已经有每一次提交,包括分歧点。 我得到这个: $ git bundle creat
我对我的分支进行了一些更改,然后意识到我忘记了我已经对所述分支进行了一些其他必要的更改。我想要的是一种将我 stash 的更改与当前更改 merge 的方法。 有办法吗? 更多的是为了方便,我最终放弃
不太确定发生了什么,但 git stash 似乎在一个糟糕的地方。 % git stash list stash@{0}: filter-branch: rewrite stash@{1}: filt
在 channel 入口条件中使用 stash:variables 时,我遇到了 Stash 问题。 模板.html {stash:embed name="pages" stash:paginate=
很多时候,在进行实验性更改之前,我需要拍摄当前工作目录的快照作为备份。这就是我所做的。 git stash git stash apply 但是我使用了一些监听磁盘更改的应用程序,它们会导致不需要的行
在我们的办公室中,我们使用没有服务器访问权限的 Stash(最大访问级别是创建分支),因此我们需要限制特定 Git 分支的推送。所以很简单,我们需要做的就是在发布后卡住我们的分支。 目前我们正在做的是
我更改了一些文件和一些新文件 git pull: 说我在几个文件中有冲突 我做到了: git stash git pull git stash pop 我预计会发生冲突,但没有发生。 相反,许多文件现
我有一个 Windows 命令脚本,旨在将 dev 分支 merge 到项目分支中。它首先读取当前分支名称、存储更改、获取并 merge 开发和项目分支,然后切换回原始分支并 pop 存储。 问题是
git stash 的联机帮助页说 pop [--index] [-q|--quiet] [] Remove a single stashed state from the stash list an
请理解场景: 1. 一天前创建了一个新分支,并将我的工作推送到那里。 2.整天忙于sublime,修改现有文件,创建一些新文件。 3. 没有添加或提交,但存储,切换到另一个分支,在那里提交并 pop
谁能解释一下它们之间的区别: git stash 对比: git stash save ? 谢谢! 最佳答案 来自docs : Calling git stash without any argume
首先我输入 git stash show。 然后输入s和tab,显示git stash show stash@{,到此为止一切正常。 但是我输入1和tab后,变成了git stash show sta
在使用 git add -p 对索引添加一些更改后,我发布了一个 git stash 但忘记添加 --keep-index。然后我就傻傻的做了一个git stash pop,我对索引的修改都没有了。有
使用 Xcode,在尝试将代码更新推送到 Github 时,系统提示我“Pull and Stash”。我不小心选择了好吧,现在我的Xcode项目是旧版本(最后一个推送到GitHub)。我怎样才能将其
我是一名优秀的程序员,十分优秀!