什么是最简单的方法来更换git中的暂存和非暂存更改? [英] What is the shortest way to swap staged and unstaged changes in git?

查看:1063
本文介绍了什么是最简单的方法来更换git中的暂存和非暂存更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果将一些更改添加到索引中,并且有一些更改未添加到索引中,那么如何交换这两组更改?

解决方案

它认为这是临时提交最容易的方法。当您尝试对变更进行重新排序时,可能会发生冲突。



使用分阶段更改进行提交,创建分支供以后使用:

  git commit -m保存已登台
git分支save-staged

$ b

对未分离的更改进行提交(如果非分离更改包含可能需要显式指定的新文件 git add <

  git commit -a -m未暂存的变更

code>

将未执行的更改重新映射到原始HEAD(可能涉及冲突解决):

  git rebase --onto HEAD ^^ HEAD ^ 

将分阶段更改重新映射到未分离的更改(可能涉及冲突解决):

  git reset --hard save-staged 
git rebase --onto HEAD @ {1} HEAD ^

最后,将索引重置为(本来)unsaged changes:

  git reset HEAD ^ 

然后将分支指针移回到原来的HEAD:

  git reset  - 软体HEAD ^ 

删除临时分支:

  git分支-D save-staged 


If some changes are added to the index and there are some changes that are not added to the index, how do I swap this two sets of changes?

解决方案

It think that this is easiest to do with temporary commits. When you have staged and unstaged commits, you have the possibility of conflicts when trying to reorder the changes.

Make a commit with the staged changes, create a branch for later use:

git commit -m "Saved staged"
git branch save-staged

Make a commit with the unstaged changes (if the unstaged changes include new files you may need to explicitly git add them first):

git commit -a -m "Unstaged changes"

Rebase the unstaged changes onto the original HEAD (may involve conflict resolution):

git rebase --onto HEAD^^ HEAD^

Rebase the staged changes onto the unstaged changes (may involve conflict resolution):

git reset --hard save-staged
git rebase --onto HEAD@{1} HEAD^

Finally, reset the index to the (originally) unstaged changes:

git reset HEAD^

And move the branch pointer back to the original HEAD:

git reset --soft HEAD^

Removed temporary branch:

git branch -D save-staged

这篇关于什么是最简单的方法来更换git中的暂存和非暂存更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆