简体   繁体   English

将所有更改提交到临时分支,同时在 master 上保持未提交

[英]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.

相关问题 在保留以前提交的所有更改的同时,将分支更新为最新主服务器的最佳方法是什么? - What's the best way to update a branch to the latest master while still keeping all the changes that were previously committed? 如何在保留原始提交历史记录的同时将分支重新建立为master? - How to rebase a branch to master while keeping the original commit history? 主机中本地未提交的更改。 需要切换到另一个分支 - Local uncommited changes in master. Need to switch to another branch git将未经更改的更改从主分支移动到新分支 - git move uncommited changes from master to new branch Git 将分支回滚到上一个提交,同时将主分支保持在它所在的位置(以及 PR 那个分支?) - Git rollback a branch to a previous commit while keeping master branch where it's at (and PR that branch?) 恢复分支上未提交的更改 - Recover uncommited changes on a branch 提交到主分支将子分支将进行更改 - Commit to master branch will sub branch will take the changes 我可以在首次提交之前创建分支,同时保持master分支完整吗? - Can I create branch before first commit while keeping master branch intact? 如何合并 git 中的分支,该分支一直在 master 中删除文件,同时在 master 分支中保持删除的文件完整? - How to merge branch in git which deleted files in master all the while keeping the deleted files intact in the master branch? 如何在保留新分支中的更改的同时将本地分支合并到更新的分支中? - How to merge local branch to an updated master while keeping changes in the new master?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM