0

Based on the following git scenario:

 C0 (master)
   \
    \
     C1-------------C5 (develop)
      \            /
       \          /
        C2--C3--C4 (feature)

I have a new uncommitted file that I want to add into master as part of commit C0. So what I did is to checkout master and then amend in order to add the file into C0.

Everything looks find but the problem I'm experiencing is that C0 hash changed and caused C1 to lose the reference.

 C0 (master)


     C1-------------C5 (develop)
      \            /
       \          /
        C2--C3--C4 (feature)

I'm basically new to git and I'm sure I did something wrong. I would appreciate any help on how to "link" C0 and C1 again.

Probably the best practice, should have been to create a new commit (C6) in master and then merge in develop, but I want to know if there is a way to solve this type of issues for future cases where, maybe "amending" into current commit is the best option.

Aleps
  • 21
  • 3
  • 1
    "Amending" a commit really always makes a *new* commit; the existing commit continues to exist unchanged. If the old commit was *only* the last commit in some branch (and not also present / visible in some other branch), the fact that it was replaced with a new-and-improved commit with different hash ID isn't obvious, unless you've written down all your hash IDs. If it *was* visible in some other way, though, whoever used the old commit, is still using the old commit, and now you have two commits visible. – torek Jul 06 '20 at 20:45

1 Answers1

1

assuming that at least one of the branches master, develop and feature are used by other people too, this kind of re-writing of git commit history should be avoided, because other's work is already based on the exact commit shared history (commit graph).

amending a commit is a history re-writing action.

for the sake of completeness, and in the case that all of these branches are private to your local repository, the way to amend commit C0 without loss of graph connectivity is to use a proper git history re-writing tool e.g. git-filter-repo

simpler history (more linear) re-writings can be achieved using git rebase -i

Nitsan Avni
  • 753
  • 6
  • 6