I need to apply a patch to the release, but I have not created a branch, what should I do?

I started working on a bunch of new features in code without branching.

These new features are not ready for deployment. However, an urgent request came in to fix another problem.

I would like to revert to the version before starting to add new features, apply the fix, and then deploy.

However, I am confused by which one should become a branch, and which version should merge onto it.

Can someone provide me a solution to this problem as a step-by-step git process to do this.

Note , I never forked using source control (now I see why I should)!

+4
source share
4 answers

What I would do is create a branch from your current state as a function branch so that you don't lose your job.

git checkout -b new-features && git push origin new-features 

Now that you have saved your current state in the branch (and pressed it on the remote control), git checkout original branch and put it back to the point in front of the current head.

The best way to do this is to use git revert . A good explanation of why and how to find it on: Cancel multiple git commits .

As soon as you revert the changes, commit and click, I would recommend that you create a branch to develop the patch. This is good practice for the same reason that people create feature branches. A good rule is to create a branch with the same or similar name / number as the problem you are working on. Make all your changes there, and when all this is done, you can pull it into any branch from which you tag your deployments.

The best part of this is that it works whether or not any changes have been transferred to the remote computer, simply and in line with best practices.

Hope this helps.

EDIT: answer the question in the comment.

"It also assumes that the changes you make are only local to your computer and are not pushing to remote branches."

This method will not work if you have already clicked. There are ways around this, but I would not recommend it.

Basically, the only difference between the two methods in their kernel is that it does git reset --hard [commit] , and the other uses git revert . The reset actually tells git to return to a specific commit, which is essentially the effect you want, but frowned if you already clicked. Since git will not allow push changes without a quick transition, and you actually deleted the history, you will need to make git push origin [branch] --force , causing the remote to also lose the changes.

Reverse actually creates a commit that adds a git story about the attacks you kill. This is better, because all discarded changes can be tracked, and anyone who pulled from this branch will not stop synchronizing. They will come back or come back when they are pulled. A good side effect of this is that if you make a mistake in your returned change, you can return it later, as this is just another commit.

+1
source

This is one way, maybe easier. It also assumes that the changes you make are only local to your computer and are not pushing to remote branches.

Assume that

  master | A - B - C' - D' 

where the sign C' and D' captures new functions that you do not want to deploy.

First create a new branch with the current commit ( master ):

 git branch new_feature 

Now we must point to commit D' , master and new_feature . This is important so as not to lose any changes that you have already made.

  master | A - B - C' - D' | new_feature 

Now we want to reset the master branch to a state without new functions, that is, to fix B We can do this with git reset --hard .
Important: If you currently have uncommitted changes, they will be lost. I recommend reading this great article on git reset to understand what it really does.

 git reset --hard B 

Now the structure will look like this:

  master | A - B - C' - D' | new_feature 

On the master branch, you can now make changes to the fix (commit E ) and click them in the hero:

  master | A - B - E \ C' - D' | new_feature 

Then you can either merge the patch into the new_feature branch, or simply reinstall it on top of the patch:

 git rebase master new_feature 

that leads to:

  master | A - B - E \ C' - D' | new_feature 

Pro Git is a really good source for learning Git, and it's free: http://git-scm.com/book .

+2
source

Now you can create a new branch, for example git checkout -b my_current_work , and then return to the master - git checkout master and return to the command that was deployed [hope you remember]. You can use, for example, the gitk command to see the graph and get the hash of the correct commit. After that you can either git checkout hash_of_the_commit or git reset --hard hash_of_the_commit (I would recommend a check, I'm sure it is safer). If this was a previous commit, you can always use a syntax like git checkout HEAD~1 , where ~ 1 means the previous commit, ~ 2 means the second last commit, etc. All your work should remain in the my_current_work branch, so you won’t lose anything. Just make sure you copy all your changes before creating a new branch.

0
source

I started working on a bunch of new features in code without branching.

Assuming you have not completed any of them, you can commit them to a temporary branch.

 git checkout -b temp_work git commit -am "temporary work" 

Then you can check master again, from there from there and do your urgent work.

 git checkout -b urgent_work 

When you're done, skip your tests, etc., then merge it back into master

 git checkout master git merge urgent_work 
0
source

All Articles