简体   繁体   English

主机中本地未提交的更改。 需要切换到另一个分支

[英]Local uncommited changes in master. Need to switch to another branch

I am WebDev intern and I have done some work in the master branch. 我是WebDev实习生,并且在master分支中做了一些工作。 And I have done a week's work without realising that I am in the master branch. 我做了一周的工作却没有意识到自己在master分支中。 I need to switch branches so that I can commit my local changes from a branch that is not the master branch. 我需要切换分支,以便可以从不是master分支的分支中提交本地更改。 What I need to do: 我需要做什么:

  • Take all the local changes from my master branch to some other branch. 将所有本地更改从我的master分支更改为其他分支。
  • Commit changes from that branch. 从该分支提交更改。
  • Give you a correct answer verification. 给您正确的答案验证。 :P :P

I went through some answers but I don't think that they are catering to my exact situation. 我回答了一些问题,但我认为它们并不能满足我的确切情况。 Thanks in advance. 提前致谢。 :) :)

The easiest thing for you to do would be to stash your working directory (and possibly stage, if you have staged any files), create a new feature branch, and then apply your stash there. 对您来说,最简单的操作是将工作目录存储(如果已暂存任何文件,则可以暂存),创建新的功能分支,然后在其中应用存储。

# from the master branch
git stash                      # stash your work
git checkout -b your_feature   # create and switch to a feature branch
git stash apply                # then apply your work to that branch

Then, you may commit your work to the your_feature branch: 然后,您可以将工作提交到your_feature分支:

git add .
git commit -m 'Finished my work'

The git stash command works by making two (or sometimes three) commits containing the contents of your working directory and stage. git stash命令的工作方式是进行两次(有时是三个)提交,这些提交包含工作目录和舞台的内容。 It then would rollback master to the point where you first began. 然后它将回滚master到您第一次开始的位置。

If you already apply some commit to the master in locally. 如果您已经在本地将某些提交应用于主服务器。 The solution that I will do in this case is: 在这种情况下,我将执行的解决方案是:

1) At first creat a new brach which will be a copy of master. 1)首先创建一个新分支,将其作为母版的副本。

git checkout -b new_branch master

2) Now push the new_branch in remote (if you want) 2)现在将new_branch推送到远程(如果需要)

git push --set-upstream origin new_branch

3) Now go to the master 3)现在去掌握

git checkout master

4) Now go to the log, and see number of commit you have done that you want to delete from master. 4)现在转到日志,查看要从主服务器删除的已完成提交次数。

git log

Lets 'N' be the number of commit you have done. 令“ N”为您已完成的提交次数。 So, to delete these commit from master use this: 因此,要从主机删除这些提交,请使用以下命令:

git reset --hard HEAD~N

For example, you want to delete recent 5 commit. 例如,您要删除最近的5次提交。 So, it will be: 因此,它将是:

git reset --hard HEAD~5

Hope it will help you. 希望对您有帮助。

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

相关问题 Git的。 在本地主服务器上重新启动本地分支。 如何忽略单个文件更改? - Git. Rebase local branch atop local master. How do I ignore a single files changes? 将未提交的更改提交到另一个分支 - Committing uncommited changes to another branch 在本地分支上,不想提交更改,但需要切换到另一个分支 - On local branch, don't want to commit changes, but need to switch to another branch 将所有更改提交到临时分支,同时在 master 上保持未提交 - Commit all changes to temporary branch while keeping them uncommited on master git将未经更改的更改从主分支移动到新分支 - git move uncommited changes from master to new branch 为什么在SVN中使用未提交的更改切换分支? - Why can you switch branch in SVN with uncommited changes? 恢复分支上未提交的更改 - Recover uncommited changes on a branch 从意外切换到另一个分支中恢复未提交的Git更改 - Recover uncommited changes in Git from accidentally switching to another branch Git:在未完成的工作中,如何在另一个分支中进行更改并返回? - Git: with uncommited work, how to make changes in another branch and come back? Git checkout to master 从另一个分支自动更新本地更改? - Git checkout to master from another branch updates automatically local changes?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM