Solution to Step 0 - START

Solution to Step 1 - Undo a single commit.

In the history, the file README.md was renamed to liesmich. Undo this change. Tip: The commit is tagged as umbenennung.

repo $ ls

from-feature
liesmich

repo $ git revert umbenennung

[main 4a063fa] Revert "umbenennen"
Date: Thu Jul 29 00:00:00 2021 +0000
1 file changed, 0 insertions(+), 0 deletions(-)
rename liesmich => README.md (100%)

repo $ ls

README.md
from-feature

Solution to Step 2 - Undo merge commit.

In the history, a feature branch was integrated via merge.file . Undo this change. Tip: The merge commit is tagged as feature-merge. Tip: The success can be recognized by the disappearance of the file from-feature.

repo $ ls

README.md
from-feature

repo $ git revert -m 1 feature-merge

[main 0cde08b] Revert "Merge branch 'feature'"
Date: Thu Jul 29 00:00:00 2021 +0000
1 file changed, 12 deletions(-)
delete mode 100644 from-feature

repo $ ls

README.md

repo $ git tag merge-reverted


Solution to Step 3 - Feature branch broken!?

A revert is often used to temporarily roll back a feature, e.g. due to a production problem. Later you want to correct the feature branch and then integrate it again. This is not so easy.

In the example, the feature branch has undergone further development. Try to merge it again. Examine the error message and the commit graph. Tip: The failed merge can be aborted with git merge --abort.

repo $ git merge feature

CONFLICT (modify/delete): from-feature deleted in HEAD and modified in feature. Version feature of from-feature left in tree.
Automatic merge failed; fix conflicts and then commit the result.

repo $ git merge --abort


repo $ git log --oneline --graph

* 0cde08b Revert "Merge branch 'feature'"
* 4a063fa Revert "umbenennen"
* 6001692 Merge branch 'feature'
|\
| * 2caf490 Created file from-feature on branch feature by bjoern.
* | 48619ce umbenennen
|/
* 50bb121 Created file README.md on branch main by bjoern.

The merge fails because Git commits that are already in the history are not merged again. In the example, this affects the commit that creates the file from-feature. It is contained in the history and in a later commit (the revert) the file was deleted. The merge conflict therefore reports that the file on one side was edited and on the other was deleted.

Solution to Step 4 - Undo merge revert again.

The trick is to revert the revert commit itself, then those changes are back on which the further development of the feature is based.

Tip: The commit is tagged as feature-merge.

repo $ git revert merge-reverted

[main d508eae] Reapply "Merge branch 'feature'"
Date: Thu Jul 29 00:00:00 2021 +0000
1 file changed, 12 insertions(+)
create mode 100644 from-feature

repo $ git merge feature

Merge made by the 'ort' strategy.
from-feature | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

repo $ git log --oneline --graph

* 91dad09 Merge branch 'feature'
|\
| * dc5cc98 : Weiterentwicklung
* | d508eae Reapply "Merge branch 'feature'"
* | 0cde08b Revert "Merge branch 'feature'"
* | 4a063fa Revert "umbenennen"
* | 6001692 Merge branch 'feature'
|\|
| * 2caf490 Created file from-feature on branch feature by bjoern.
* | 48619ce umbenennen
|/
* 50bb121 Created file README.md on branch main by bjoern.

repo $ git log --oneline from-feature

dc5cc98 : Weiterentwicklung
2caf490 Created file from-feature on branch feature by bjoern.

To the exercise

To the overview