简体   繁体   English

git stash 应用特定索引

[英]git stash apply specific index

I forked and cloned from upstream https://github.com/F5Networks/k8s-bigip-ctlr , made some local changes in my development branch 'vli-dev', during this process, the upstream made some changes, so I stashed my local changes, rebased my local development branch 'vli-dev' on the upstream master branch, now I want to git stash apply my local changes one by one to the rebased development branch, but following problem occurs:我从上游https://github.com/F5Networks/k8s-bigip-ctlr分叉和克隆,在我的开发分支'vli-dev'中做了一些本地更改,在此过程中,上游做了一些更改,所以我藏了我的本地更改,将我的本地开发分支'vli-dev'重新定位在上游主分支上,现在我想 git stash 将我的本地更改一一应用到重新定位的开发分支,但出现以下问题:

$ git stash list
stash@{0}: WIP on vli-dev: 3ef5efd ConfigMap serverssl support with 
f5ServerSslProfileAnnotation
stash@{1}: WIP on vli-dev: 1408dc3 Enable configmap to add custom irule
stash@{2}: WIP on vli-dev: bd6d985 Allow user to attach custom irule to Ingress
stash@{3}: WIP on vli-dev: 2452696 Allow ingress to attach X-Forwarded-For iRule
stash@{4}: WIP on vli-dev: cd01ce5 Route health monitor always default from http monitor regardless what's configured in route health monitor annotation, this patch fix it

$ git stash apply 0
error: Your local changes to the following files would be overwritten by merge:
pkg/appmanager/resourceConfig.go
schemas/bigip-virtual-server_v0.1.7.json
Please commit your changes or stash them before you merge.
Aborting

I noticed the local changes are actually the changes stashed in "stash@{1}"我注意到本地更改实际上是隐藏在“stash@{1}”中的更改

it appears when I git stash apply index 0, the changes in index 1 got applied to the files being changed by index 1, index 0 changes is not applied, how do I resolve this?当我 git stash apply index 0 时出现,索引 1 中的更改已应用于索引 1 更改的文件,未应用索引 0 更改,我该如何解决? my intention is to apply stashed index one by one to resolve any conflicting changes with the upstream, and the create pull request for upstream.我的意图是一个一个地应用隐藏索引来解决与上游的任何冲突更改,以及为上游创建拉取请求。

It sounds like you're using stashes to try to do what rebase does, instead of just letting rebase do it.听起来你正在使用 stashes 来尝试做 rebase 所做的事情,而不是仅仅让 rebase 去做。 The only real purpose of stash is to set aside uncommitted changes so they won't be "in the way" of some immediate operation you want to perform. stash 的唯一真正目的是搁置未提交的更改,这样它们就不会“妨碍”您要执行的某些即时操作。 Once changes are committed, there's no reason to stash them - and in fact, what you're trying to do with stashes is exactly what rebase was designed to do in the first place.一旦更改被提交,就没有理由存储它们——事实上,你试图用存储做的事情正是 rebase 最初设计的目的。

Now I'm assuming you don't currently have any uncommitted changes that you want to preserve.现在我假设您目前没有任何要保留的未提交更改。 You can use git status to confirm what uncommitted changes, if any, you have.您可以使用git status来确认您有哪些未提交的更改(如果有)。 Once your work tree is clean, I would do this:一旦你的工作树是干净的,我会这样做:

(1) Rewind your local branch to its state before you started stashing things. (1) 在你开始存储东西之前,将你的本地分支倒回它的状态。 You can use the reflog for this您可以为此使用 reflog

git reflog vli-dev

and this will show you all the commits vli-dev has referred to.这将向您显示vli-dev提到的所有提交。 Find the last local commit you had made.查找您所做的最后一次本地提交。 It will have a name like vli-dev@{14} .它的名称将类似于vli-dev@{14} (The number in braces will indicate how many changes ago, so 14 is just an example.) Then you would (大括号中的数字表示之前有多少变化,所以14只是一个例子。)那么你会

git checkout vli-dev
git reset --hard vli-dev@{14}

to return your local branch to that state, restoring all the changes you had stashed.将您的本地分支返回到该状态,恢复您隐藏的所有更改。 This also undoes the rebase, so next you need to这也撤消了变基,所以接下来你需要

git rebase origin/master 

This will copy the changes from each of your vli-dev commits into a new commit based at the newly-fetched master commit.这会将您的每个vli-dev提交的更改复制到基于新获取的master提交的新提交中。

Now, it would not be unreasonable to be concerned whether the intermediate commits created in this way are actually introducing bugs.现在,担心以这种方式创建的中间提交是否真的引入了错误并不是没有道理的。 (This is my strongest reservation about many common uses of rebase .) You can certainly check each one out and test it. (这是我对rebase的许多常见用途最强烈的保留意见。)您当然可以检查每一个并进行测试。 If you find an error at some intermediate state, you'll have to decide how much hassle it's worth to fix.如果您在某个中间状态发现错误,则必须决定修复它的麻烦程度。 You could, at that point, create a new branch from the broken commit, make the changes so that it passes tests, git commit --amend , then rebase the remaining commits onto that newly-amended commit.此时,您可以从损坏的提交创建一个新分支,进行更改以使其通过测试, git commit --amend ,然后将剩余的提交重新设置为新修改的提交。

The other thing to do is clean up all of those now-unnecessary stashes.要做的另一件事是清理所有那些现在不需要的藏匿处。 If you had a stash of truly-uncommitted changes, you'll want to apply that on your rebased branch;如果您有一些真正未提交的更改,您将希望将其应用到您的 rebased 分支上; but the rest can be dropped ( git stash drop ).但其余的可以删除( git stash drop )。 Or, if you're absolutely sure that none of the stashes have important data, you could或者,如果您绝对确定没有任何藏品有重要数据,您可以

rm .git/refs/stash
rm .git/logs/refs/stash

I want to apply specific stash from the list and for this I used git stash pop stash@{2}我想应用列表中的特定存储,为此我使用了 git stash pop stash@{2}

if you use this command then it will apply that particular stash and remove from stashed list, if you don't want to remove stash then just use git stash apply stash@{2}如果您使用此命令,那么它将应用该特定存储并从存储列表中删除,如果您不想删除存储,则只需使用 git stash apply stash@{2}

if you want to remove specific stash then use git stash drop stash@{1}如果你想删除特定的存储然后使用 git stash drop stash@{1}

if you want to clean all stash from list then use git stash clear如果你想清除列表中的所有存储然后使用 git stash clear

reference: https://www.atlassian.com/git/tutorials/saving-changes/git-stash参考: https ://www.atlassian.com/git/tutorials/saving-changes/git-stash

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM