Update from 2021 (8 years later): you would not use git checkout
anymore, but git switch
git switch -c try_to_commit 2fb14b7
Why does this not squash?
Because you are merging a parent (past) commit (3e7a060) to a new one 2fb14b7
| | * e2a1c13 (HEAD, refs/stash, trying_to_squash) WIP on temp: 2fb14b7 hw7
| | |\
| | | * 429b1de index on temp: 2fb14b7 added hw7
| | |/
| | * 2fb14b7 <-- added hw7 (more recent commit)
| | * 39224ad <-- (another_branch) added hw3
| | * fe9252d <-- hw2 added in master
| | * 3e7a060 <-- adding hw2.txt (past old commit)
I would rather create the branch on the past commit, and squash-merge the more recent commit:
git switch -c try_to_commit 3e7a060
git merge --squash 2fb14b7
What does this do to my repository?
git rebase --interactive 3e7a060
It attempts to replay the current branch try_to_commit
on top of 3e7a060: that should allow to pick/squash commits, but don't forget to then replay e2a1c13 on top of the replayed branch.
I would rather rebase the all branch try_to_commit, made from e2a1c13 instead of 3e7a060, and using the Git 2.18, Q2 2018, --rebase-merges
option:
git switch -c try_to_commit c39d943
git rebase --rebase-merges --interactive 3e7a060
Note that the message (nothing to squash)Already up-to-date
will change with git 2.32 (Q2 2021): a few variants of the informational message "Already up-to-date
" has been rephrased.
See commit ad9322d (02 May 2021) by Josh Soref (jsoref
).
See commit 80cde95 (02 May 2021) by Eric Sunshine (sunshineco
).
(Merged by Junio C Hamano -- gitster
-- in commit 5feebdd, 11 May 2021)
merge
: fix swapped "up to date" message components
Co-authored-by: Eric Sunshine
Signed-off-by: Josh Soref
Signed-off-by: Eric Sunshine
The rewrite of git-merge
(man) from shell to C in 1c7b76b ("Build in merge", 2008-07-07, Git v1.6.0-rc0 -- merge) accidentally transformed the message:
Already up-to-date. (nothing to squash)
to:
(nothing to squash)Already up-to-date.
due to reversed printf()
arguments.
This problem has gone unnoticed despite being touched over the years by:
- 7f87aff ("Teach/Fix pull/fetch -q/-v options", 2008-11-15, Git v1.6.1-rc1 -- merge)
- bacec47 ("
i18n
: git-merge
basic messages", 2011-02-22, Git v1.7.5-rc1 -- merge)
- tangentially by bef4830 ("
i18n
: merge: mark messages for translation", 2016-06-17, Git v2.10.0-rc0 -- merge listed in batch #5)
- 7560f54 (
treewide
: correct several , 2017-08-23, Git v2.15.0-rc0 -- merge listed in batch #7) (treewide: correct several "up-to-date" to "up to date", 2017-08-23).
Fix it by restoring the message to its intended order.