有时我一起压了一堆承诺。通常,我的命令遵循以下模式:
git reset --hard HEAD~4
git merge --squash HEAD@{1}
git commit今天,虽然,在第二步,我被什么东西分心了(松鼠?松懈?Facebook?)我忘了用HEAD@{1}结束git merge --squash命令。但它神奇地做了我想做的事。
我找不到任何文档显示忽略合并的目标将默认为HEAD@{1},但很好的结果是它成功了。
有这方面的文件吗?
我从git help merge中看到了以下内容,但它似乎没有回答这个问题:
--squash, --no-squash
Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit). This
allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).
With --no-squash perform the merge and commit the result. This option can be used to override --squash.
With --squash, --commit is not allowed, and will fail.发布于 2022-02-03 11:21:36
跑步:
git merge(无选择和无论据)“指”:
git merge @{upstream}添加选项(如--squash )不会改变这一点,因此:
git merge --squash是以下的同义词:
git merge --squash @{upstream}@{upstream}语法意味着通过当前分支的上游定位提交指向的位置。master的上游非常典型地是origin/master。dev的上游非常典型地是origin/dev。这种模式重复。使用git rev-parse可以找到实际的上游。
git rev-parse --symbolic-full-name @{upstream}例如,在用于Git的Git存储库的Git克隆中生成:
$ git rev-parse --symbolic-full-name @{u}
refs/remotes/origin/master也就是说,我在master上,上游是origin/master。(对于我来说,这个特定的克隆主要是一个参考克隆,所以我只是让它的主副本与Git存储库的其他各种副本保持同步。@{u}是编写@{upstream}的一种更短的方法:更少的记忆,但更容易输入。)不管提交@{u}的意思是什么,这都是吉特壁球合并的意思。
作为jthill noted in a comment,您应该考虑将git reset --soft作为您的特定目标。软重置移动当前分支,而不触及索引和工作树,这避免了git merge --squash必须执行的工作。生成的索引和工作树将是相同的,而且由于--squash不创建.git/MERGE_HEAD (并确实暗示--no-commit),最终的git commit也将以相同的方式运行。
https://stackoverflow.com/questions/70962338
复制相似问题