Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

exercise: Interactive rebase that creates empty commit #349

Open
JKrag opened this issue Dec 14, 2022 · 0 comments
Open

exercise: Interactive rebase that creates empty commit #349

JKrag opened this issue Dec 14, 2022 · 0 comments
Labels
New exercise Ideas about new exercises to be created

Comments

@JKrag
Copy link
Contributor

JKrag commented Dec 14, 2022

I came across an interesting case during a interactive rebase. I had a history where one commit made a small change, and the following commit was a small fix to the same line. During the interactive rebase, I made commit two a fixup of commit one, but this happened to reduce the end result to something that was already on master, which interrupts the rebase with the following interesting message:

No changes
You asked to amend the most recent commit, but doing so would make
it empty. You can repeat your command with --allow-empty, or you can
remove the commit entirely with "git reset HEAD^".
Could not apply f138369... fix shellcheck again

I thought this was an interesting scenario to make a kata out of.

Here is the example I had:

Original code:

if [ -z "$URL" ]; then
  echo "Please specify an endpoint to call with the -u switch."
  usage
  exit 1;
fi

Existing recent commit on master by other dev (to fix shellcheck error):

 if [ -z "$URL" ]; then
   echo "Please specify an endpoint to call with the -u switch."
   usage
-  exit 1;
 fi

On the "feature" branch, I had the following two commits trying to fix the same problem:

First commit A:

 if [ -z "$URL" ]; then
   echo "Please specify an endpoint to call with the -u switch."
-  usage
-  exit 1;
+  usage || exit 1
 fi

and the fixup commit B:

 if [ -z "$URL" ]; then
   echo "Please specify an endpoint to call with the -u switch."
-  usage || exit 1
+  usage
 fi

This feature branch was originally based on a older master commit before the shellcheck fix, and then updated with a rebase on the newly fetched master, which of course changed the diff of commit A to no longer have the - exit 1; line. I am not entirely sure that this part is relevant for the case.

In the interactive rebase done to clean up this branch that also contains other changes, I made B a fixup of A. The net result was that is ends up being the exact same change as already on master. This leads to the interesting "error" mentioned above, instead of the maybe expected suggestion to just do a git rebase --skip

@JKrag JKrag added the New exercise Ideas about new exercises to be created label Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New exercise Ideas about new exercises to be created
Projects
None yet
Development

No branches or pull requests

1 participant