简体   繁体   English

Git repo分支错误修复

[英]Git repo branching mistake fix

I was trying to create a new branch from the master branch of my organization repository, and yet when I checked how this branch was, I found that it was some commits behind the master branch. 我试图从我的组织存储库的主分支创建一个新的分支,然而当我检查这个分支是什么时,我发现它是主分支后面的一些提交。 I found that I had forgot to do a pull into my branch before creating that branch. 我发现在创建分支之前我忘记了进入我的分支。 Should I contact the admin of the repository before resetting it to the correct state, and what are the commands I should perform to get it in line with the latest commits? 我应该在将其重置为正确的状态之前联系存储库的管理员吗?为了使其与最新的提交保持一致,我应该执行哪些命令?

This command should rebase your current branch on top of the local master branch: 此命令应该在本地master分支之上重新绑定当前分支:

$ git rebase master

This assumes you pulled the changes on master already. 这假设您已经在master上删除了更改。 Alternatively you can rebase directly on top of the remote branch after fetch: 或者,您可以在获取后直接在远程分支的顶部进行rebase:

$ git rebase origin/master

This assumes your remote is called origin (which is often the case). 假设您的遥控器被称为origin (通常是这种情况)。

make sure you checkout into master and pull the changes using: 确保您签入主人并使用以下方式提取更改:

git pull 

rebase with master 与主人一起改变

git rebase origin/master -i

force push your branch using 用力推动你的分支

git push origin <your branch> --force

click on your commit to check that no files are different in your branch from master 单击您的提交以检查分支中的文件与主文件不同

The other two answers are correct. 另外两个答案是正确的。

If you just created your branches, then you could also just delete them and start over. 如果您刚刚创建了分支,那么您也可以删除它们并重新开始。

To delete your remote branch: 要删除远程分支:

git push origin --delete <your branch>

to delete your local branch: 删除您的本地分支:

git branch -D <your branch>

You shouldn't need to contact the Administrator to delete branches that you created. 您无需联系管理员即可删除您创建的分支。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM