Dilep Dev
Dilep Dev

Reputation: 93

Git, What is the recommended applying bug changes in a older commit

I have a code public repository with the following structure, new features are implemented by breaking off a new branch from master and merging it back.


   (bugfix)
      |
      U
     /          (master)
    /              |
A--B--C--D--E...J--K
   |
 (production)

Lets say there is a bug in the commit which production is pointing to (B).

  1. What is the recommended/best way(s) to apply the bug fix to Production in Git?
  2. Is it possible to apply the bugfix(U) to later features/ commits (C, D, E and so on), if so what recommended way(s) on doing it?
                           (master)
                              |
A---B---C'---D'---E' ... J'---K' 
    |
(production)
  1. Is it possible to have the commit C point to U ?
     (bugfix)              (master)
        |                     |
A---B---U---C---D---E ... J---K 
    |
(production)

if so how do i have the changes applied to C, D, E ..

     (bugfix)                  (master)
        |                         |
A---B---U---C'---D'---E' ... J'---K' 
    |
(production)

Edits

  1. Clarifying the question
    • I don't want to merge (U) to master, lets say this is because I don't want (K) to be in production yet
    • I will be moving production from C, D, E... to K not directly to K

Upvotes: 0

Views: 91

Answers (1)

hide1nbush
hide1nbush

Reputation: 935

I highly recommend to use online git playground to emulate your process, those emulators include: https://git-school.github.io/visualizing-git/#free (disclaimer: I'm not the developer of this site)

Visualized Demo:this process visual demo

Firstly, I think those things could only happened with bad branch management.

If you don't want K to be in production yet, why would you merge/commit K into the master branch.

To deal with this issue, you can

  1. Checkout and make a new branch(dev) just like current master branch
  2. Back to master branch, and reset head on B
  3. Cherry-pick U onto master branch
  4. Merge/Rebase your new master into your dev branch.
  5. Finally, it may looks like:
     (bugfix, master)
        |
A---B---U
    |
(production)
                          (possible merge request commit, dev)
                              |
A---B---C---D---E ... J---K---L
    |
(production)

Upvotes: 2

Related Questions