[英]Merge local master branch into remote sub branch
I have cloned a repository from master branch and did lots of modifications.我已经从 master 分支克隆了一个存储库并做了很多修改。 Suddenly I remembered that I'm using the master brach and I wanted to commit it to newly created remote branch not the master branch.Actually I'm very new to git.
突然我想起我正在使用主分支,我想将它提交到新创建的远程分支而不是主分支。实际上我对 git 非常陌生。 please help me,Thank you
请帮助我,谢谢
If you made changes to wrong branch then do git checkout -b newBranchName
.如果您对错误的分支进行了更改,请执行
git checkout -b newBranchName
。 This will move all changes to new branch named newBranchName
这会将所有更改移动到名为
newBranchName
的新分支
Then do git branch
to see which branch are you currently working on.然后做
git branch
,看看你当前在哪个分支上工作。
If this is the newBranchName
then do如果这是
newBranchName
然后做
git add . //stages all changed files
git commit -m "any message here" //commit with a message
git push -u origin newBranchName //push local branch to remote with name newBranchName
Doing this will push your local branch to a new remote branch named newBranchName
这样做会将您的本地分支推送到名为
newBranchName
的新远程分支
Now doing git checkout master
will again take you back to you local master branch.现在执行
git checkout master
将再次将您带回本地 master 分支。
Cross check which branch are you currently at by git branch
通过
git branch
If this shows master with green color or *master
then do git reset --hard HEAD
to revert back the changes you have made in your local.如果这显示 master 为绿色或
*master
然后执行git reset --hard HEAD
以恢复您在本地所做的更改。
Once you reset it then your local master branch will be exactly same as remote master branch.一旦你重置它,那么你的本地主分支将与远程主分支完全相同。
This is a common workflow mistake.这是一个常见的工作流程错误。 One simple option is to create a new branch from your current point in
master
, then revert your local master
branch back to the point right before you started working:一个简单的选择是从
master
中的当前点创建一个新分支,然后将本地master
分支恢复到开始工作之前的点:
# from master
# git commit any outstanding changes
git branch feature
git reset --hard HEAD~2 # replace 2 with the actual number of commits you did make
This assumes that you made two commits to your local master
branch before you realized you were on the wrong branch.这假设您在意识到您在错误的分支上之前对本地
master
分支进行了两次提交。 The hard reset command simply removes those commits, which however are now still part of the feature
branch.硬重置命令只是删除那些提交,但现在仍然是
feature
分支的一部分。 You may now push feature
to the remote if you want to do that.如果您想这样做,您现在可以将
feature
推送到遥控器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.