[英]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: 我需要做什么:
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.