简体   繁体   English

压制远程分支中的任意提交

[英]Squash arbitrary commits in a remote branch

I am a bit of a noob with Git and was tasked to clean up the history of a feature I developed recently. 我对Git有点陌生,受命清理我最近开发的功能的历史。 I have a similar setup to this fellow here . 在这里有与此人相似的设置。 I also kind of want to accomplish the same thing, but I want to squash to specific commits. 我也想完成同样的事情,但是我想压缩特定的提交。 For example, if my commits are commit1, commit2, ..., commitN , I want to make it so that commit1, commit2, ... are squashed to commitX ; 例如,如果我的提交是commit1,commit2,...,commitN ,那么我要使其变为将commit1,commit2,...压缩到commitX commitX+1, commitX+2, ... are squashed to commitY ; commitX + 1,commitX + 2,...被压缩为commitY ; etc. 等等

I understand that this is possible with the command 我了解使用命令可以实现

git rebase -i origin/*branch_name*

but the problem is that when I run that command, I get this: 但是问题是当我运行该命令时,我得到了:

noop

# Rebase a112005..a112005 onto a112005 (1 command(s))
...

As far as I understand, the last and the first commits should be displayed here, but it only sees the last commit. 据我了解,应该在此处显示最后一次提交和第一次提交,但只能看到最后一次提交。 When I try to run pick or squash with any other commit it says: 当我尝试通过任何其他提交运行选择或压扁时,它说:

error: could not apply *commit hash*... *commit message*

which obviously means that it finds the commit since it knows its message, but for some reason, it doesn't even see it as editable. 这显然意味着它知道提交信息后就找到了提交,但是由于某种原因,它甚至认为它不可编辑。 Anybody have any idea how I can fix this? 有人知道我该如何解决吗? Also if someone recommends either a better terminal-based synchronization system for my setup or a better way of organizing my stuff, I'd be grateful. 另外,如果有人为我的设置推荐一个更好的基于终端的同步系统或一种更好的组织方式,我将不胜感激。

You cannot do anything on a remote-tracking branch. 您无法在远程跟踪分支上执行任何操作。 In fact, you cannot be "on" a remote-tracking branch in the first place. 实际上,首先您不能在远程跟踪分支上。 (The git checkout command is the one that puts you "on a branch", as git status shows; but it will not put you on a remote-tracking branch, only on a local branch.) (如git status所示, git checkout命令是使您“进入分支”的命令;但它不会使您进入远程跟踪分支,而仅使它进入本地分支。)

In general, to make something happen in a Git repository, you must make it happen in your Git repository, using your branch-names. 在一般情况下,要在一个Git仓库事情发生,你必须在你的 Git仓库发生, 使用分支的名称。

When you want something to happen in someone else 's Git repository (such as the one on origin ), the way you do this is to first, get everything set up in your repository, then use git push to ask them to take your work into their repository and set one of their branch names to match. 当你想要的东西在别人的Git仓库发生(如一个在origin ),你这样做是为了第一,得到一切设立在你的仓库的方式,然后使用git push他们把你的工作进入存储库,并设置分支名称之一以匹配。

If you ask them—the other Git that controls that other repository—to set their branch-name to point to some specific commit, 1 and they agree, then , at that point, your Git will set your origin/ branch-name to point to that same commit, since their Git has told yours that, yes, it is now using that particular commit for that particular branch. 如果您要求他们(控制该其他存储库的另一个Git)将其branch-name设置为指向某个特定提交1, 并且他们同意, 那么到那时, 您的 Git会将您的origin/ branch-name为指向到同一提交,因为他们的 Git告诉您,是的,它现在正在将该特定提交用于该特定分支。


1 They need to have that commit, but your git push will give it to them first, if they don't already have it. 1,他们需要承诺,但你的git push将首先提供给他们,如果他们不已经拥有了它。 That's how git push works. 这就是git push工作方式。 First, it hands over the set of objects that you have that they don't that they need in order to accept your requests; 首先,它移交了您需要的一组对象,它们不需要它们来接受您的请求; then, it hands over a series of requests: "Please set branch B1 to commit 1234567... , and/or branch B2 to commit 89abcde... , and/or set tag T to ...". 然后,它会发出一系列请求:“请设置分支B1提交1234567 ...和/或分支B2提交89abcde ... ,和/或将标签T设置为...”。 Their Git obeys none, some, or all of these requests, sending either "ok" or "no, and here's why" responses for each one. 他们的Git不服从任何请求,不接受全部请求或全部接受,对每个请求都发送“ ok”或“ no,这就是原因”的回复。

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

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