Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keeping Child Branch up to Date with Parent when using commit --amend

Tags:

git

My current Git repo has three branches: mainline, feature_a, and feature_b. The history is as follows:

  1. mainline was cloned from a remote repo
  2. feature_a branch was checked out from mainline
  3. Changes were made on feature_a and committed as commit_a
  4. feature_b branch was checked out from feature_a
  5. Changes were made on feature_b and committed as commit_b
  6. Changes were made to feature_a and amended to commit_a

How do I update the feature_b branch with the changes amended to commit_a?

like image 245
Thomas Avatar asked Oct 12 '16 00:10

Thomas


People also ask

Why does git say my master branch is already up to date even though it is not?

If the current branch is not outdated compared to the one you pull from, pull will say Already up-to-date. even if you have local changes in your working directory. git pull is concerned with branches, not the working tree — it will comment on the working tree only if there are changes which interfere with the merge.

What happens when you amend a commit?

The git commit –amend command lets you modify your last commit. You can change your log message and the files that appear in the commit. The old commit is replaced with a new commit which means that when you amend your old commit it will no longer be visible in the project history.

Why git merge says already up to date?

The message “Already up-to-date” means that all the changes from the branch you're trying to merge have already been merged to the branch you're currently on. More specifically it means that the branch you're trying to merge is a parent of your current branch.


1 Answers

Your history probably looks something like this:

           A' [feature_a]
          /
*--*--*--* [mainline]
          \
           A [original feature_a]
            \
             B [feature_b]

Commit A is the original commit you made on feature_a. When you amended the commit with git commit --amend, it created a new commit, A'.

You'll need to rebase feature_b to attach it to the new commit A'. Do:

git rebase --onto feature_a A feature_b

(You might also be able to get away with simply doing git rebase feature_a feature_b, but I'm not sure how this will work since you amended commit A.)

Now your history will look like this:

             B' [feature_b]
            /
           A' [feature_a]
          /
*--*--*--* [mainline]

Technically commits A and B are still in the repo, but since they aren't being used, Git will garbage-collect them later.

like image 193
Scott Weldon Avatar answered Oct 05 '22 14:10

Scott Weldon