[英]Commit all changes to temporary branch while keeping them uncommited on master
I am wondering what is the correct approach in the following situation.我想知道在以下情况下正确的方法是什么。
I am working on master
branch locally and I have multiple uncommited changes that I don't want to commit to origin/master
yet .我在本地的
master
分支上工作,我有多个未提交的更改,我不想提交到origin/master
yet 。
I would like to commit my current changes to some newly created origin/temporary
branch (so someone else can quickly run the current stage of my workspace on his own) while keeping all the changes in local master
as they are, to be able to commit them to origin/master
later at some point.我想将我当前的更改提交到一些新创建
origin/temporary
分支(以便其他人可以自己快速运行我的工作区的当前阶段),同时保持本地master
中的所有更改,以便能够提交他们稍后在某个时候origin/master
。
I assume I have to use git stash
in some order, but I am not sure...我假设我必须按某种顺序使用
git stash
,但我不确定......
Edit:编辑:
Some of you have suggested, that I can just merge temporary
into master
.你们中的一些人建议,我可以将
temporary
合并到master
中。 This is not the case, as I'm not assuming that the temporary branch contains anything to be accepted nor anything valid.事实并非如此,因为我不假设临时分支包含任何要接受的内容或任何有效内容。 It's purpose is just to quickly show the current code stage that will change surely before it is good enough for commiting to master or to be properly reviewed.
它的目的只是快速显示当前代码阶段,在它足够好以提交到 master 或被适当审查之前肯定会改变。
This is the reason why I do not want to treat those changes as real changes later in the tree, they are just ugly.这就是为什么我不想在树的后面将这些更改视为真正的更改的原因,它们只是丑陋。
Here is one possibility:这是一种可能性:
# from current master
git add .
git commit -m 'WIP: temporary commit'
git branch temporary
git reset --mixed HEAD~1
For an explanation, the above is first adding all files to the index, and making a commit on master
.为了解释,上面是首先将所有文件添加到索引中,然后在
master
上进行提交。 You ultimately don't want that commit there, but we'll come back to that later.你最终不希望在那里提交,但我们稍后会回来讨论。 From this point, we branch off a new branch
temporary
, without actually switching to that branch.从这一点开始,我们分支出一个
temporary
的新分支,而不实际切换到该分支。 Then, from master
we do a mixed reset back one commit.然后,我们从
master
做一个混合重置返回一个提交。 This will leave your index empty, with all your original changes in the working directory.这将使您的索引为空,所有原始更改都在工作目录中。 Note that the temporary commit is now not part of the
master
branch, but is the HEAD of the new temporary
branch.请注意,临时提交现在不是
master
分支的一部分,而是新temporary
分支的 HEAD。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.