A revert has no rule, its default message does not follow Message format, and git blame stops at it

Open
#53 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
git, javascript, shell

Research direction

Read CONTRIBUTING.md, the commit skill, and tools/trace-decision/collect-lib.mjs, especially findReferences; first check #49 for the merge strategy decision. Update the revert guidance and trace behavior described in the proposal, including tests for following the reverted commit hash. Done means revert messages follow Message format, the commit skill covers reverting PRs and merges, and trace-decision follows revert references.

Written by the indexing model from the issue text.

Description

type/feature
Problem to solve

CONTRIBUTING.md has no rule for a revert. A revert overturns a decision, but the tools make a revert commit that the rules do not accept, and the history after a revert is harder to trace.

Tests with Git 2.47.1 in temporary repos:

  1. The message. git revert writes Revert "<subject>" and This reverts commit <hash>.. The subject has no type, the body has no Why, and nothing gives Supersedes:, which Message format requires when a commit overturns a decision. The Revert button of a merged PR on GitHub makes a commit with the same default message. CI does not check commit messages, so only the commit skill or a review can find it.
  2. The trace. A file was deleted and, later, a git revert of the deletion restored it. git blame showed the revert commit for each line, also with -C -C. git log --follow -- <path> showed the complete history: the commit that added the file, the deletion and the revert. The script of trace-decision starts from git blame, so it stops at the revert commit. It follows references to issues and PRs in commit messages, but not the commit hash in This reverts commit <hash>.
  3. A merge commit. This repo merges each PR with a merge commit.
    • git revert <merge> fails with "is a merge but no -m option was given". git revert -m 1 <merge> reverts the PR.
    • After that revert, a new merge of the same branch brought back nothing. Git reported that the branch was already merged. Only a revert of the revert brought the change back.

A deletion alone is traceable. git log -- <path> shows the history of a deleted path, and git log --diff-filter=D --name-only finds deletions when the path is not known. The commit that deletes the file gives the reason in Why.

Proposal
  1. Add a rule to Commits or Message format in CONTRIBUTING.md: a revert is a decision, and its message follows Message format.
    • The subject has the type of the change, for example docs: restore the setup guide, not Revert "…".
    • Why gives the reason for the revert.
    • Supersedes: names the reverted decision by its subject.
    • The body keeps the line This reverts commit <hash>.. The reverted commit is in main, so its hash does not change.
  2. Give the steps for a revert in the commit skill: git revert --no-commit <commit>, then a commit with the message above. For a merge commit, git revert --no-commit -m 1 <merge>. To bring a reverted PR back, revert the revert. A new merge of the old branch does not bring it back.
  3. Change the script of trace-decision: when a commit message has This reverts commit <hash>., read that commit too. Then a line that git blame gives to a revert commit leads to the reverted decision.

If #49 chooses squash merge, item 3 of the Problem and the -m 1 step go away: each PR is one normal commit in main, and a revert of it is a normal revert.

Version

c3185e8

More information
  • Message format and Supersedes: in CONTRIBUTING.md.
  • tools/trace-decision/collect-lib.mjs: findReferences finds issue and PR references only.
  • #51 proposes that mechanical steps go into scripts with tests, as item 3 does for the trace.
Dominant language
Shell
Stars
1
Forks
0
Avg merge
6h 59m
Merged PRs (30d)
26

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from c-w-z/commit-decision-record

All issues in c-w-z/commit-decision-record

Similar issues

More Shell/Bash issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.