+
Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion docs/contribute/general/git.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ the quality of the commits and their respective commit messages.
******************

Authors name and e-mail address are part of the commit (and thus be part of the commit history).
They must match the name and e-mail used for eclipse registration. They can be specified via the
They must match the name and e-mail used for Eclipse registration. They can be specified via the
.gitconfig file:

.. code-block::
Expand Down Expand Up @@ -178,3 +178,58 @@ Example
repositories.

Also-by: Some Bodyelse <somebodyelse@nowhere.com>

********************
Tips and Tricks
********************

Deal with Long-Living Feature Branches
======================================

Long-living feature branches are a common source of complicated merges.
The root cause typically lies in planning issues:
Overlapping changes are planned into parallel units of work. Examples are "developer
B refactors module X" while "developer A adds a feature to module X". With documents
as code, the same applies for requirements, design, architecture, and other artifacts.
The larger the units of work, the longer the lifetime of branches, and the more likely
it is that such overlaps occur and conflicts arise.

So, there are three stategies to deal with this:

1. Avoid long-living branches by splitting work into smaller units of work and merge
them frequently into the main branch.
2. If long-living branches are unavoidable, perform the changes in a way that anticipate this
and make conflicts less likely. For example, in case of documentation changes write the new
content in a separate file until the work is done. Then, only in a last step integrate the
new content into the structure which exists in the main branch.
3. Accept the fact that conflicts may arise and deal with them when they occur.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if "merge frequently" is the same as 1?

Copy link
Contributor Author

@opajonk opajonk Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean... 1 says "merge frequently into main", but for that you must be able to do that --> split work into smaller units. This may not be always possible, hence there are strategies 2 and 3 as well.

3 is not "merge frequently into main"; if anything, it is "merge frequently into the feature branch". However, you can also deal with the conflicts at the end, once. It may or may not be less work.


Correcting Mistakes
===================

Sometimes it happens that mistakes are made in the commit history.
This can usually be corrected as long as they are not merged to main.

Examples of problematic history include:

- Multiple, consecutive commits by the same author, like "draft one", "after review", "forgotten in previous commit".
In case the squash commit option is not used (see above), such commits should be squashed into a single commit, with a well-written commit message.
- Merges from the main branch into a feature branch.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually both examples are only relevant for non squash commits, which are not recommended anyway ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though not recommended, anybody getting onboarded should know directly how to commit and how to rebase (instead of merging with main, which is provided in github as a single button press), otherwise they may learn hard before a pull-request.
So my quest is rather, how do we make sure ev1 can avoid tricky squashing after some 3 months working on a branch / pull-request with multiple authors.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't work 3 months on a branch with multiple authors?

Seriously. I strongly advertise for merging multiple times per day.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well that actually was the case with all feature requests, that were started early in spring and are being merged right now. So it seems to be a usual working construct at least for bigger contributions, such as feature requests that also demanded quite some work to be done before they can be accepted.

Should we have some recommendations for such situations, or maybe recommendations on how to avoid them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added something for this: strategies how to avoid or deal with long-lived feature branches.

Instead, the feature branch should be rebased on top of the main branch.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not on collaborative branches with multiple authors

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a warning

This preserves a linear history.
However, be careful with branches that are worked on by multiple persons.

A strategy which can be used to correct the commit history of a branch is to use a feature of git called 'interactive rebase'.
Afterwards, the (now cleaned-up) branch can be force-pushed to the remote repository.
This works also if there is already a pull-request open for this branch.
The Git Documentation contains `a well-written section <https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History>`_ about "rewriting history".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That section does not cover simple rebases, that would be https://git-scm.com/book/en/v2/Git-Branching-Rebasing and merging at https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging or maybe even just branching in general at https://git-scm.com/book/en/v2/Git-Branching-Branches-in-a-Nutshell

We need to be careful not to write yet another (and very incomplete) git tutorial here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is correct, so I did not link it. This section is only about the case of "repairing an already botched history". Hence interactive rebase, or "step by step cherry picking onto new branch" are the right strategies.

However, to be fair, this is not simple when you do it for the first time.

Another strategy is to create a new branch from the main branch and cherry-pick the relevant commits from the old branch to the new branch.
Then, push the new branch to the remote repository and create a new pull-request.
This strategy is easier to understand, but has the downside that the discussion in the old pull-request is not automatically transferred to the new pull-request.

The most efficient approach is to do either clean-up together with someone experienced in Git.
Such a [pairing session](https://en.wikipedia.org/wiki/Pair_programming) can show you how to "think Git".
However, be confident: as long as you have not force-pushed the branch to GitHub, all changes you did are local and can be undone easily.
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载