Reputation: 4652
For this particular project, I work on two branches "develop" and "master" I have been doing some stuff on "develop" and committed the changes. The client then informed me that they didn't want to go live with the change.
I need to go back, without effecting these changing as I have other changes to make on the repository before this goes live. Is there an elegant way to do this without me losing any work?
I was thinking:
EDIT: I now have three branches:
master
, develop
new
New contains all of the new features I don't want to make live yet
Develop contains the working copy.
I ran git reset --hard [NUMBER]
This has reverted develop
back to a place before the changes on new
I did a few minor changes on develop
and ran:
git add .
git commit -m "Fix - Contact form"
git push origin develop
But got:
! [rejected] develop -> develop (non-fast-forward)
Updates were rejected because the tip of your current branch is behind
Upvotes: 1
Views: 95
Reputation: 29166
First thing first: you will never loose anything with Git
unless you really want to i.e. removing a branch, removing commits from the reflog
and executing git gc
...
If I understand your situation you have this:
* 3456789 (master)
| * 2345678 What I dont want yet (develop)
| * 1234567 What I want
* |
|/
*
So you want to create a new branch develop2
reset your branch develop
to 1234567
, and merge it to master
:
$ git checkout -b develop2 develop
$ git checkout develop
$ git reset --hard 1234567
$ git merge master
And you eventually obtain this:
* 5678912 (master, develop)
|\
* |
| | * 2345678 What I dont want yet (develop2)
| |/
| * 1234567 What I want
* |
|/
*
Upvotes: 2