My current Git repo has three branches: mainline
, feature_a
, and feature_b
. The history is as follows:
mainline
was cloned from a remote repofeature_a
branch was checked out from mainline
feature_a
and committed as commit_a
feature_b
branch was checked out from feature_a
feature_b
and committed as commit_b
feature_a
and amended to commit_a
How do I update the feature_b
branch with the changes amended to commit_a
?
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With