简体   繁体   English

Git,从本地分支(我的电脑)更新远程分支(bitbucket存储库)

[英]Git, update remote branch ( bitbucket repository ) from local branch ( my pc )

I want to update my repository which isn't tracked, and I made changes to the file locally. 我想更新未跟踪的存储库,因此我在本地对文件进行了更改。

What I did is. 我所做的是。

git fetch

git branch -a - List all the branches git branch -a列出所有分支

git diff --stat --color master origin/master - This compares my local to the remote. git diff --stat --color master origin/master将本地与远程进行比较。

then I do git push which gives me this output. 然后我做git push ,这给了我这个输出。

Updates were rejected because the tip of your branch is behind... 由于the tip of your branch is behind...因此更新被拒绝the tip of your branch is behind...

but I don't want to pull the changes from the remote repo, because I made some changes locally. 但我不想从远程存储库中提取更改,因为我在本地进行了一些更改。 and I want to push my changes to the remote repo. 我想将更改推送到远程仓库。

BEWARE : if you don't really understand what you are doing, it could have irreversible consequences. 注意 :如果您不太了解自己在做什么,可能会产生不可逆转的后果。

If you don't care about overwriting changes in the remote repo, use git push -f 如果您不在乎覆盖远程仓库中的更改,请使用git push -f

This happens when there have been changes to both your local branch and the remote branch and the reason why you are not allowed to push your changes to the remote branch is because the remote changes could get overwritten by your local changes if you were to just push the changes. 当您的本地分支和远程分支都发生更改时,就会发生这种情况,并且之所以不允许您将更改推送到远程分支是因为,如果您只想推送,则远程更改可能会被本地更改覆盖变化。

One way to solve this is to use a feature in git called rebase . 解决此问题的一种方法是在git中使用一个称为rebase的功能。 What it does is that it replays your changes on top of the remote branch, to ensure that your branch is up-to-date and then builds on the remote branch. 它的作用是在远程分支的顶部重放您的更改,以确保您的分支是最新的,然后在远程分支上进行构建。

You should be able to solve this problem by updating your local branch by running this command: git pull --rebase . 您应该能够通过运行以下命令更新本地分支来解决此问题: git pull --rebase This will pull the remote changes and then replay your local changes on top of those. 这将拉动远程更改,然后在这些更改之上重播本地更改。

You can read more on git-rebase here: https://git-scm.com/book/en/v2/Git-Branching-Rebasing 您可以在这里阅读有关git-rebase的更多信息: https : //git-scm.com/book/en/v2/Git-Branching-Rebasing

If, however, you really want to overwrite the remote branch, there is also a --force option to git push . 但是,如果您确实要覆盖远程分支,则还可以使用--force选项进行git push I would not recommend it unless you really know what you are doing. 除非您真的知道自己在做什么,否则我不建议您这样做。 More information on what options are available for pushing can be found here: https://git-scm.com/docs/git-push 有关可用于推送的选项的更多信息,可以在这里找到: https : //git-scm.com/docs/git-push

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

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