Commit Reversal

Asked

Viewed 198 times

1

I have a question, I would like to return to a certain commit and assign this commit to a given branch without losing history, for example.

I have a development branch, where it is read by a URL, when I am developing and I want to show my client what I did in development, I commit it is good, but it can happen that I did not go to production at that exact moment, then I would have to return to the initial commit put this commit assigned to the development branch and still get the history.

there is how to do this?

  • Cherry-pick? I think that’s what you want

2 answers

2

One of the branch strategies is Feature branch, where you develop each Feature into a specific branch and then merge them into an integrator branch. The integration branch is what you send to the release, and so you only do the integration of the code when you’re sure to enter the release.

In addition to branch strategies, having a release plan is important because when you’re about to make the delivery, you should have already passed tests, deploy in an approval environment, and so your code will already be integrated into the integrative branch, which is the origin of the build of Integration.

Another way for you to separate Features on delivery is to do with Feature flag, so if the customer does not approve at this time, the functionality is just turned off in an administration panel, but this technique is more complex and is used in large business environments or in very complex software.

  • For those who want to delve into some common workflows: https://www.atlassian.com/git/tutorials/comparing-workflows

0


From what I understand, I believe you want this in your development branch:

--> C0 ---> C1 --> C1'
  1. C0 is the commit before yours
  2. C1 is when you committed the change and showed it to the client
  3. C1' is when you reversed the change, but kept the history of what happened: you committed C1 to develop.

So it’s better to use the git revert passing the hash from commit C1:

git revert 25d025e3317f59882d03b7938ee500e86d858c33

To find the commit hash, use the following command:

git log

It will be the first record (from bottom to top), similar to this: 25d025e3317f59882d03b7938ee500e86d858c33

If you want to come back with the change after revert, use the same commit number to apply it again to your branch:

git cherry-pick 25d025e3317f59882d03b7938ee500e86d858c33
  • So I tested this, it worked in parts, the commit I want was not assigned to the master. I think you should use something similar to "reset"

  • Then you’d better follow the egomesbrandao’s answer: put your change in a branch and present your branch to the customer, without "contaminating" the master in any time.

  • The problem I would have "contaminated" the master understood? Type here where work the master is what goes to the site, so I’ve been doing things, but it didn’t work out, so we have to return the commits to the master without losing the history understood?

  • Bruno, I get it. But I recommend that you try to change this flow. As I said in another team, the branch master should be "sacred": everything that goes in there is to stay, is our production code. You should show the client the ready code on a separate branch and only use the master when they have hammered the change. I recommend adding what you just told me in your question, are important information of your flow that will help us answer better.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.