0

I wanted to understand how Git handles the following situation in the Feature Branch Workflow: On the master branch a file is deleted and then that delete is committed. On a feature branch the same file is deleted and that delete is committed. Then the master branch is rebased over the feature branch.

[user@host public]$ git status # On branch master nothing to commit (working directory clean) [user@host public]$ git checkout -b master_test Switched to a new branch 'master_test' [user@host public]$ git checkout master Switched to branch 'master' [user@host public]$ git rm test.txt rm 'public/test.txt' [user@host public]$ git commit -m "Remove test file" [master 0cfee96] Remove test file 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 public/test.txt [user@host public]$ git checkout master_test Switched to branch 'master_test' [user@host public]$ git rm test.txt rm 'public/test.txt' [user@host public]$ git commit -m "Remove test file on the feature branch" [master_test f6468dc] Remove test file on the feature branch 0 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 public/test.txt [user@host public]$ git checkout master Switched to branch 'master' Your branch is ahead of 'origin/master' by 1 commit. [user@host public]$ git rebase master master_test First, rewinding head to replay your work on top of it... Nothing to do. [user@host public]$ git log -1 commit 0cfee962f7cab143d7a2835e0ecd50d8cef7230e Author: leonard <[email protected]> Date: Mon Nov 9 10:47:28 2015 +0000 Remove test file [user@host public]$ git branch master * master_test 

Is Git happy to discard the Remove test file on the feature branch commit because it sees it as being the same? Will it always override the feature branch commit with the one from master (when rebasing this way) and would the same thing happen when combined with multiple commits?

0

1 Answer 1

2

According to git rebase --help:

Note that any commits in HEAD which introduce the same textual changes as a commit in HEAD.. are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped).

Which one is overwritten depends on the direction you chose when rebasing, i.e. rebase master on master_test or vice versa. Branch names do not hold any special meaning to git.

According to the man pages (any commits), yes, the same thing would happen in the case of multiple commits.

Somewhat related question.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.