git 没有什么可以比较的。没什么可比较的,分支是完全不同的提交历史
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23344320/
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
There isn't anything to compare. Nothing to compare, branches are entirely different commit histories
提问by Hyman
I have a CMS theme installed on my machine. I'm tracking changes to it via git and decided to back it up on GitHub so I could share those changes.
我的机器上安装了 CMS 主题。我正在通过 git 跟踪对它的更改,并决定在 GitHub 上备份它,以便我可以共享这些更改。
The theme as provided is also available on GitHub. On my machine I have added this as a remote upstream. Now I can easily see the changes between my master and the remote upstream by using the following command:
提供的主题也可以在 GitHub 上找到。在我的机器上,我将它添加为远程上游。现在,我可以使用以下命令轻松查看我的 master 和远程上游之间的更改:
git diff --color master upstream/number
If I could add the remote upstream on GitHub I could easily share these changes. Is it possible to set this relationship on GitHub?
如果我可以在 GitHub 上添加远程上游,我可以轻松分享这些更改。是否可以在 GitHub 上设置这种关系?
I have tried the following:
我尝试了以下方法:
git push -u origin upstreambranch
which adds an upstreambranch
to the master on GitHub. However trying to
compare both branches doesn't work, the result I get on GitHub is that: "There
isn't anything to compare"
它upstreambranch
在 GitHub 上向 master添加了一个。然而,试图比较两个分支不起作用,我在 GitHub 上得到的结果是:“没有什么可以比较的”
Is there an alternative way to compare these?
有没有其他方法来比较这些?
回答by
The Short Answer
简短的回答
It looks like GitHub won't let you compare the branches because they don't actually share any of the same history at all,even though they may share much of the same files and code.
看起来 GitHub 不允许您比较分支,因为它们实际上根本不共享任何相同的历史记录,即使它们可能共享许多相同的文件和代码。
Here is a screenshot of the temporary fork I made of your repo, where I tried to
compare master
with the upstreambranch
, like you described. Notice the error
message:
这是我用你的 repo 制作的临时叉的屏幕截图,我试图master
与upstreambranch
你描述的进行比较。注意错误信息:
It says:
它说:
There isn't anything to compare.
master
andupstreambranch
are entirely different commit histories.
没有什么可以比较的。
master
并且upstreambranch
是完全不同的提交历史。
The Long Answer
长答案
You probably downloaded the original source and added it to a completely new repo instead of cloning the original repo, right? Doing that will make it so that the history of your repo will be completely differentfrom the history of the original repo, since your new repo won't have any of the same commits with the same sha IDs.
您可能下载了原始源并将其添加到一个全新的存储库中,而不是克隆原始存储库,对吗?这样做将使您的存储库的历史记录与原始存储库的历史记录完全不同,因为您的新存储库不会有任何具有相同 sha ID 的相同提交。
You can see that by doing a reverse log of your master
branch and the
upstreambranch
:
您可以通过执行master
分支的反向日志和以下内容来看到
upstreambranch
:
# Your first commit, see commit sha
git log --reverse master
commit c548d7b1b16b0350d7fbdb3ff1cfedcb38051397 # <== HERE
Author: Padraic Stack <[email protected]>
Date: Wed Apr 2 15:11:28 2014 +0100
First commit of everything
# First commit sha of the original repo
git log --reverse upstreambranch
commit 105a12817234033c45b4dc7522ff3103f473a862 # <== THERE
Author: Jeremy Boggs <[email protected]>
Date: Mon Feb 22 16:00:53 2010 +0000
Creates repo directories for the Seasons theme.
Solutions
解决方案
If you redo your commits on top of the original history, you should then be able to compare the branches. There are several different ways that you can redo your commits, including
如果您在原始历史记录之上重做提交,那么您应该能够比较分支。有几种不同的方法可以重做提交,包括
git rebase --onto
and
和
git cherry-pick
You also can redo each commit manually, if you have to.
如果需要,您也可以手动重做每个提交。
回答by Kunal Tyagi
I solve my issue using these commands
我使用这些命令解决了我的问题
git checkout [BRANCH]
git branch master [BRANCH] -f
git checkout master
git push origin master -f
回答by jthill
This looks like undesirable behavior on github's part, but it's fairly easy to fix. What you want to do is to rebase your branch on a reasonable (anyreasonable) commit in the existing history. What you can do is to fetch the github repo and find which tree in its history is most similar to the one you started with. Start this way:
对 github 来说,这看起来像是不受欢迎的行为,但它很容易修复。您想要做的是根据现有历史记录中的合理(任何合理)提交来重新设置分支。您可以做的是获取 github 存储库并找到其历史记录中的哪棵树与您开始使用的树最相似。以这种方式开始:
git remote add github u://r/l
git fetch github
myroot=`git rev-list master --max-parents=0`
root_tree=`git rev-parse $myroot^{tree}`
github_base=`git log --pretty=%H\ %T github/master | sed -n "s/$root_tree//p"`
With any luck, that will find you a commit in the github history that has the exact tree you started with. Assuming it does,
运气好的话,你会在 github 历史记录中找到一个提交,其中包含你开始使用的确切树。假设确实如此,
git rebase --onto $github_base $myroot master
and you're done.
你就完成了。
If that doesn't find a matching tree, you get to find a nearest approximation. Here's one way to get a rough estimate of the differences:
如果没有找到匹配的树,您可以找到最近的近似值。以下是粗略估计差异的一种方法:
git log --pretty='echo %H $(git diff-tree -p -b -U0 '$myroot:' %T|wc -l)' github/master \
| sh
which will count the lines in a minimized diff between the tree of each commit in the github/master
history and your root tree. It seems reasonable to hope for a nice small difference, you could eyeball the actual diffs on it before calling that the github_base
commit and doing the rebase above.
这将计算github/master
历史中每个提交的树与根树之间最小差异中的行数。希望有一个很好的小差异似乎是合理的,您可以在调用github_base
提交并执行上面的 rebase之前观察它的实际差异。
回答by Clint Clinton
From the experiment branch
来自实验分支
git rebase master
git push -f origin <experiment-branch>
This creates a common commit history to be able to compare both branches.
这会创建一个共同的提交历史,以便能够比较两个分支。
回答by Sergey Frolov
If you know from which commit issue started, you can reset your branch to that commit and then merge them.
如果您知道从哪个提交问题开始,您可以将您的分支重置为该提交,然后合并它们。
回答by dev_khan
A more simple approach where you can't mingle with the master.
一种更简单的方法,您不能与主人打成一片。
Consider i have master
and JIRA-1234
branch and when i am trying to merge JIRA-1234
to master
i am getting the above issue so please follow below steps:-
你看我有master
和JIRA-1234
分支,当我试图合并JIRA-1234
到master
我收到上述问题,因此请按照下列步骤操作: -
From
JIRA-1234
cut a branchJIRA-1234-rebase
(Its a temp branch and can have any name. I have takenJIRA-1234-rebase
to be meaningful.)git checkout JIRA-1234
git checkout -b JIRA-1234-rebase
The above command will create a new branch
JIRA-1234-rebase
and will checkout it.Now we will rebase our
master
.git rebase master
(This is executed in the same branchJIRA-1234-rebase
)You will see a window showing the commit history from first commit till the last commit on
JIRA-1234-rebase
. So if we have 98 commits then it will rebase them 1 by 1 and you will see something like 1/98.- Here we just need to pick the commit we want so if you want this commit then don't do anything and just HIT
Esc
then:q!
and HITENTER
. There would be some changes in case of conflict and you need to resolve this conflict and then add the files by
git add <FILE_NAME>
.Now do
git rebase continue
it will take you to rebase 2/98 and similarly you have to go through all the 98 commits and resolve all of them and remeber we need to add the files in each commit.Finally you can now push these commits and then raise Pull Request by
git push
orgit push origin JIRA-1234-rebase
From
JIRA-1234
cut a branchJIRA-1234-rebase
(它是一个临时分支,可以有任何名字。我认为JIRA-1234-rebase
有意义。)git checkout JIRA-1234
git checkout -b JIRA-1234-rebase
上面的命令将创建一个新分支
JIRA-1234-rebase
并检出它。现在我们将重新调整我们的
master
.git rebase master
(这是在同一个分支中执行的JIRA-1234-rebase
)您将看到一个窗口,显示从第一次提交到最后一次提交的提交历史记录
JIRA-1234-rebase
。因此,如果我们有 98 次提交,那么它会将它们 1 x 1 变基,您将看到类似 1/98 的内容。- 在这里,我们只需要选择我们想要的提交,所以如果你想要这个提交,那么不要做任何事情,只是 HIT
Esc
then:q!
和 HITENTER
。 如果发生冲突,将会有一些更改,您需要解决此冲突,然后通过以下方式添加文件
git add <FILE_NAME>
.现在做
git rebase continue
它会带你到 2/98 变基,同样你必须经历所有 98 次提交并解决所有这些问题,并记住我们需要在每次提交中添加文件。最后,您现在可以推送这些提交,然后通过以下方式提出拉取请求
git push
或者git push origin JIRA-1234-rebase
回答by Lakshay
This happened with me yesterday cause I downloaded the code from original repo and try to pushed it on my forked repo, spend so much time on searching for solving "Unable to push error" and pushed it forcefully.
这发生在我昨天,因为我从原始 repo 下载了代码并尝试将其推送到我的分叉 repo 上,花了很多时间寻找解决“无法推送错误”的问题并强行推送。
Solution:
解决方案:
Simply Refork the repo by deleting previous one and clone the repo from forked repo to the new folder.
只需通过删除前一个 repo 来重新分叉 repo,然后将 repo 从分叉的 repo 克隆到新文件夹。
Replace the file with old one in new folder and push it to repo and do a new pull request.
用新文件夹中的旧文件替换文件并将其推送到仓库并执行新的拉取请求。
回答by JSkyS
Top guy is probably right that you downloaded instead of cloning the repo at start. Here is a easy solution without getting too technical.
您下载而不是在开始时克隆存储库可能是正确的。这是一个简单的解决方案,不会太技术化。
- In a new editor window, clone your repo in another directory.
- Make a new branch.
- Then copy from your your edited editor window into your new repo by copy paste.
- 在新的编辑器窗口中,将您的存储库克隆到另一个目录中。
- 新建一个分支。
- 然后通过复制粘贴从您编辑过的编辑器窗口复制到您的新存储库中。
Make sure that all your edits are copied over by looking at your older github branch.
通过查看旧的 github 分支,确保复制了所有编辑。
回答by kimberrypi
I had mine solved by overriding the branch:
我通过覆盖分支解决了我的问题:
My case: I wanted to override whatever code is in the develop
with version_2
.
我的情况:我想覆盖develop
with中的任何代码version_2
。
- delete the local copy of conflicting branch:
- 删除冲突分支的本地副本:
git checkout version_2
git branch -D develop
- checkout a fresh branch from the
version_2
and force push to git:
- 从 签出一个新分支
version_2
并强制推送到 git:
git checkout -b `develop`
git push origin `develop`
I didn't need to rebase. But in my case, I didn't need to take code from my old code.
我不需要变基。但就我而言,我不需要从旧代码中提取代码。
回答by Gui-Alucard
I solved that problem. In my case when i did “git clone” in one directory of my choice without do “git init” inside of that repository. Then I moved in to the cloned repository, where already have a “.git” (is a git repository i.e. do not need a “git init”) and finally I started do my changes or anything.
我解决了那个问题。在我的情况下,当我在我选择的一个目录中执行“git clone”而没有在该存储库内执行“git init”时。然后我转移到克隆的存储库,那里已经有一个“.git”(是一个 git 存储库,即不需要“git init”),最后我开始做我的更改或任何事情。
It probably doesn't solve the problem but shows you how to avoid it.
它可能无法解决问题,但会向您展示如何避免它。
The command git clone should be a “cd” command imbued if no submodule exists.
如果不存在子模块,命令 git clone 应该是一个“cd”命令。