-
Notifications
You must be signed in to change notification settings - Fork 60
docs: Add section to git doc about fixing problems #1643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
9953e5c
4a1aa35
30e8a49
d2f8ba9
93e455a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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:: | ||
|
@@ -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. | ||
|
||
|
||
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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not on collaborative branches with multiple authors There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.