1

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?

Hoa
  • 19,858
  • 28
  • 78
  • 107
  • 2
    "squash" means to combine two commits into a single commit. If you squash a commit with sensitive information with the commit before it, you will get a new commit that still contains the sensitive information. I don't think that is really what you want. You should either skip or edit the commit with sensitive information in order to remove that information from your commit history. – Code-Apprentice Jun 21 '18 at 03:26
  • Agreed - I want to remove the sensitive information, then squash that commit with the one before it (containing the sensitive information) – Hoa Jun 21 '18 at 03:28

1 Answers1

6

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

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • I don't want to preserve the sensitive info - I want to obliterate it. – Hoa Jun 21 '18 at 03:28
  • 1
    @Hoa By "preserve" I mean they will appear in the interactive rebase menu if you run `git rebase -i -p origin/master~4 master` and then you can choose to preserve or obliterate them. – ElpieKay Jun 21 '18 at 03:35