英文:
git stash pop retrieved only some changes
问题
我使用git stash show
命令存储了我能看到的所有更改:
valenta@WSKKOS879 MINGW64 /c/Daten/Projekte/nextgen_coolant/HvUnit (feature_184932)
$ git stash show
Sources/Common/CommonSettings.h | 2 +-
Sources/IARProject/HvUnit.ewp | 148 ++++++++++++---------
.../InterComSignalIf_DiagRequests.c | 3 +
Sources/MCAL/Config/Dio_cfg.cfg | 8 +-
Sources/MCAL/Config/Opb_cfg.cfg | 2 +
Sources/Main/main.c | 17 +--
Sources/SimpleRealTimeScheduler/Srts.c | 22 +--
Sources/SimpleRealTimeScheduler/Srts.h | 2 +-
Sources/SimpleRealTimeScheduler/Srts_Cfg.c | 2 +-
Sources/SimpleRealTimeScheduler/Srts_Slots_Cfg.c | 4 +-
10 files changed, 110 insertions(+), 100 deletions(-)
然后,我想使用git stash pop
命令将它们取回:
valenta@WSKKOS879 MINGW64 /c/Daten/Projekte/nextgen_coolant/HvUnit (feature_184932)
$ git stash pop
On branch feature_184932
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: Sources/IARProject/HvUnit.ewp
modified: Sources/IoHwAb/InterCom/InterComSignalIf/InterComSignalIf_DiagRequests.c
modified: Sources/MCAL/Config/Dio_cfg.cfg
modified: Sources/MCAL/Config/Opb_cfg.cfg
Untracked files:
(use "git add <file>..." to include in what will be committed)
.vscode/
build/
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (d9c5f5a5121c5d8e183d0efa7e9533c53420a344)
但只有其中一些被取回,为什么?现在我该怎么做?
英文:
I stashed all changes which I could see all with git stash show
command:
valenta@WSKKOS879 MINGW64 /c/Daten/Projekte/nextgen_coolant/HvUnit (feature_184932)
$ git stash show
Sources/Common/CommonSettings.h | 2 +-
Sources/IARProject/HvUnit.ewp | 148 ++++++++++++---------
.../InterComSignalIf_DiagRequests.c | 3 +
Sources/MCAL/Config/Dio_cfg.cfg | 8 +-
Sources/MCAL/Config/Opb_cfg.cfg | 2 +
Sources/Main/main.c | 17 +--
Sources/SimpleRealTimeScheduler/Srts.c | 22 +--
Sources/SimpleRealTimeScheduler/Srts.h | 2 +-
Sources/SimpleRealTimeScheduler/Srts_Cfg.c | 2 +-
Sources/SimpleRealTimeScheduler/Srts_Slots_Cfg.c | 4 +-
10 files changed, 110 insertions(+), 100 deletions(-)
It then I wanted to retrieve them back with git stash pop
command:
valenta@WSKKOS879 MINGW64 /c/Daten/Projekte/nextgen_coolant/HvUnit (feature_184932)
$ git stash pop
On branch feature_184932
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: Sources/IARProject/HvUnit.ewp
modified: Sources/IoHwAb/InterCom/InterComSignalIf/InterComSignalIf_DiagRequests.c
modified: Sources/MCAL/Config/Dio_cfg.cfg
modified: Sources/MCAL/Config/Opb_cfg.cfg
Untracked files:
(use "git add <file>..." to include in what will be committed)
.vscode/
build/
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (d9c5f5a5121c5d8e183d0efa7e9533c53420a344)
But only some of them were retrieved, why? what can I do now?
答案1
得分: 1
或许你没有意识到:git stash
实际上是通过创建一个提交(一个常规的合并提交)来存储 Git 中的更改。你可以通过运行 git log --oneline --graph stash
查看它的视图:
$ git log --oneline --graph stash
* df1c341(refs/stash)WIP on master: ba7d0ba create a.txt
|\
| * d9f6a3e index on master: ba7d0ba create a.txt
|/
* ba7d0ba(HEAD -> master)create a.txt
* ...
- 顶部提交本身保存了你的工作树的内容(磁盘上的文件,包括尚未暂存的更改)
- "index ..." 提交保存了索引的内容(已暂存的文件)
正如你所见,这些提交是基于你运行 git stash
时的活动提交。
当你运行 git stash show
时,git
会显示你的存储提交与其基础提交(图中的提交 ba7d0ba
)之间的差异。
当你应用一个存储时,它会应用在你的新活动提交上,这可能与基础提交不同。一些更改可能已经是你的新 feature_184932
分支的一部分,不再显示为差异。
git
提到了曾经是你的 head 存储的提交的 SHA,你可以使用该 SHA 将其内容与当前磁盘上的文件进行比较:
git diff d9c5f5a5121c5d8e183d0efa7e9533c53420a344
# 或者在图形差异查看器中:
git difftool -d d9c5f5a5121c5d8e183d0efa7e9533c53420a344
然后,你可以评估是否有一些更改丢失。
请注意,此差异将包括自从你运行 git stash
以来在你的 feature_184932
分支上提交的内容,因此查看差异需要理解什么是预期的差异,什么是丢失的代码片段。
英文:
preamble:
perhaps you weren't aware of it: git stash
actually stores changes in git by creating a commit (a regular merge commit). You can have a view of that by running git log --oneline --graph stash
:
$ git log --oneline --graph stash
* df1c341 (refs/stash) WIP on master: ba7d0ba create a.txt
|\
| * d9f6a3e index on master: ba7d0ba create a.txt
|/
* ba7d0ba (HEAD -> master) create a.txt
* ...
- the top commit itself holds the content of your worktree (files on disk, including not yet staged changes)
- the "index ..." commit holds the content of the index (the staged files)
As you can see, these commits are based on the active commit at the moment when you run git stash
.
When you run git stash show
, git
shows you the differences of your stash commit when compared to its base commit (commit ba7d0ba
in the diagram above).
When you apply a stash, it is applied on your new active commit, which may be different from that base commit. Some changes may already be part of your new feature_184932
branch for example, and not show up as differences anymore.
git
mentions the sha of the commit that used to be your head stash
, you can use that sha to compare its content to your current files on disk :
git diff d9c5f5a5121c5d8e183d0efa7e9533c53420a344
# or in a graphical diff viewer:
git difftool -d d9c5f5a5121c5d8e183d0efa7e9533c53420a344
You can then evaluate if some changes are missing.
Note that this diff will include content that was committed on your feature_184932
branch since you ran git stash
, so viewing the diff requires understanding what is an expected difference and what is a missing piece of code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论