My git log command produces the following:
commit 568a9783f75b0c1ab12499beb32b518e19ab60c0 (HEAD -> master, origin/master)
Merge: 7428e09 e7c1537
...
commit 7428e0947bb47a3fdc46a1ea053bd86aa87934c8
...
commit e7c15371f39f4183c5f8c0645051a022851902f2
Merge: e715e8a ae7d067
...
commit ae7d06745891c215cc2980df520656509e4e36ef
...
At commit 7428e0947bb47a3fdc46a1ea053bd86aa87934c8 (second above), some sensitive information was accidentally checked into the repository and I therefore want to squash it with previous commits.
I'm trying to follow the instructions here:
How to squash commits in git after they have been pushed?
First, I have removed the sensitive information and then commited the changes:
git add .
git commit -a -m "Remove sensitive info"
Git log now looks like:
commit d6d1954c10bd71cc33f24222d1e36b3116eb7775 (HEAD -> master)
...
Remove sensitive info
commit 568a9783f75b0c1ab12499beb32b518e19ab60c0 (origin/master)
Merge: 7428e09 e7c1537
commit 7428e0947bb47a3fdc46a1ea053bd86aa87934c8
commit e7c15371f39f4183c5f8c0645051a022851902f2
Merge: e715e8a ae7d067
...
commit ae7d06745891c215cc2980df520656509e4e36ef
...
Now I run:
git rebase -i origin/master~4 master
and I get:
...
pick ae7d067 ...
pick d6d1954 Remove sensitive info
I don't understand what's happened to:
568a9783f75b0c1ab12499beb32b518e19ab60c0
7428e0947bb47a3fdc46a1ea053bd86aa87934c8
e7c15371f39f4183c5f8c0645051a022851902f2
How do I get the above three commits to appear so I can manually choose which commits to squash?
They are merge commits. To preserve them, you need -p
or --preserve-merges
in git rebase
.
git rebase -i -p origin/master~4 master
Reference:https://www.git-scm.com/docs/git-rebase#git-rebase--p