git 我能做些什么来解决“1次提交背后的主人”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34118404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What I can do to resolve "1 commit behind master"?
提问by Roman Yavoriv
After pushing I've been seeing this message at remote repository:
推送后,我一直在远程存储库中看到此消息:
1 commit behind master.
This merge has conflicts that must be resolved before it can be committed.
To manually merge these changes into TA20footerLast run the following commands:
> git checkout 7c891f50c557
#Note: This will create a detached head!
> git merge remotes/origin/master
1 在 master 后面提交。
此合并具有必须在提交之前解决的冲突。
要手动将这些更改合并到 TA20footerLast 中,请运行以下命令:
> git 结帐 7c891f50c557
#注意:这将创建一个分离的头!
> git merge remotes/origin/master
回答by ash
I know this is a late answer but it could help others.
我知道这是一个迟到的答案,但它可以帮助其他人。
Before you begin, if you are uncomfortable with a command line, you can do all the following steps using SourceTree, GitExtension, GitHub Desktopor your favorite tool.
在开始之前,如果您对命令行不满意,您可以使用SourceTree、GitExtension、GitHub Desktop或您喜欢的工具执行以下所有步骤。
To solve the issue, you might have two scenarios:
要解决此问题,您可能有两种情况:
1) Fix only remote repository branch which is behind commit
1) 仅修复提交后面的远程存储库分支
Example: Both branches are on the remote side
示例:两个分支都在远程端
ahead === Master branch
前进 === 主分支
behind === Develop branch
后面 === 开发分支
Solution:
解决方案:
i) Clone the repository to the local workspace: this will give you the Master branch which is ahead with commit
i) 将存储库克隆到本地工作区:这将为您提供在提交之前的 Master 分支
git clone repositoryUrl
ii) Create a branch with Develop name and checkout to that branch locally
ii) 使用 Develop 名称创建一个分支并在本地结帐到该分支
git checkout -b DevelopBranchName // this command creates and checkout the branch
iii) Pull from the remote Develop branch
iii) 从远程 Develop 分支拉取
git pull origin DevelopBranchName
iv) Merge the local Develop branch with the remote Develop branch
iv) 将本地 Develop 分支与远程 Develop 分支合并
git merge origin develop
v) Push the merged branch to the remote Develop branch
v) 将合并的分支推送到远程的 Develop 分支
git push origin develop
2) Local Master branch is behind the remote Master branch
2)本地Master分支在远程Master分支后面
This means every locally created branch is behind.
这意味着每个本地创建的分支都落后了。
Before preceding, you have to commit or stash all the changes you made on the branch that is behind commits.
在之前,您必须提交或存储您在提交后面的分支上所做的所有更改。
Solution:
解决方案:
i) Checkout your local Master branch
i) 签出您当地的 Master 分支
git checkout master
ii) Pull from remote Master branch
ii) 从远程主分支拉取
git pull origin master
Now your local Master is in sync with the remote Branch but other local remotes are not in sync with your local Master branch because of the above command. To fix that:
现在您的本地 Master 与远程分支同步,但由于上述命令,其他本地远程与您的本地 Master 分支不同步。要解决这个问题:
1) Checkout the branch that is behind your local Master branch
1) 签出本地 Master 分支后面的分支
git checkout BranchNameBehindCommit
2) Merge with the local Master branch
2)与本地Master分支合并
git merge master // Now your branch is in sync with local Master branch
If this branchis on the remote repository, you have to push your changes
如果此分支在远程存储库上,则必须推送更改
git push origin branchBehindCommit
回答by Gurdeep Singh
Clone your fork:
git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
Add remote from original repository in your forked repository:
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
Updating your fork from original repo to keep up with their changes:
git pull upstream master
git push
克隆你的叉子:
git clone [email protected]:YOUR-USERNAME/YOUR-FORKED-REPO.git
在您的分叉存储库中添加来自原始存储库的远程:
cd into/cloned/fork-repo
git remote add upstream git://github.com/ORIGINAL-DEV-USERNAME/REPO-YOU-FORKED-FROM.git
git fetch upstream
从原始 repo 更新您的 fork 以跟上它们的变化:
git pull upstream master
git push
回答by Bayram Binbir
If your branch is behind by master then do:
如果您的分支落后于 master,则执行以下操作:
git checkout master (you are switching your branch to master)
git pull
git checkout yourBranch (switch back to your branch)
git merge master
After merging it, check if there is a conflict or not.
If there is NO CONFLICT then:
合并后,检查是否有冲突。
如果没有冲突,则:
git push
If there is a conflict then fix your file(s), then:
如果存在冲突,则修复您的文件,然后:
git add yourFile(s)
git commit -m 'updating my branch'
git push
回答by Ashwani
If the message is "n commits behind master."
如果消息是“n commits behind master”。
You need to rebase your dev branch with master. You got the above message because after checking out dev branch master, the master branch got new commit and has moved ahead. You need to get those new commits to your dev branch. Steps:
您需要使用 master 重新设置 dev 分支。您收到上述消息是因为在检出 dev 分支 master 之后,master 分支获得了新的提交并继续前进。您需要将这些新提交提交到您的开发分支。脚步:
git checkout master
git pull #this will update your local master
git checkout yourDevBranch
git rebase master
there can be some merge conflicts which you have to resolve.
可能存在一些您必须解决的合并冲突。
回答by shaurya airi
If the branch is behind master, then delete the remote branch. Then go to local branch and run :
如果分支在 master 后面,则删除远程分支。然后转到本地分支并运行:
git pull origin master --rebase
Then, again push the branch to origin:
然后,再次将分支推到原点:
git push -u origin <branch-name>
回答by hacks8878
Suppose currently in your branch myBranch
Do the following :-
假设当前在您的分支中myBranch
执行以下操作:-
git status
If all changes are committed
如果所有更改都已提交
git pull origin master
If changes are not committed than
如果未提交更改,则
git add .
git commit -m"commit changes"
git pull origin master
Check if there are any conflicts than resolve and commit changes
检查是否存在任何冲突,而不是解决和提交更改
git add .
git commit -m"resolved conflicts message"
And than push
而不是推
git push origin myBranch
回答by Hiran D.A Walawage
Use
用
git cherry-pick <commit-hash>
So this will pick your behind commit to git location you are on.
因此,这将选择您对 git 位置的背后提交。