0

I have two servers. One for development and one for production. Both are in Gitlab. I work alone and now I have messed up my git origin.

In development server:

  1. I created a new branch and made some changes with commit.No push
  2. Then in the same branch I made some other changes with another commit.No push
  3. Last in the same branch I made some other changes with another commit.

But I made a serious mistake. After third commit I pushed and merged with origin. This was wrong because I wanted only the last commit to merge with origin. All other was testing. I though that I can work these in parallel but probably I did it with wrong way.

Now when I try in production server to pull the changes I get all three commits.

In production server I have a branch called "right-branch" which everything is ok. What I want is to clone this branch to origin master and pull origin to development server so I can start again. How can I do that?

G. G.
  • 279
  • 1
  • 4
  • 14
  • Possible duplicate of [I need to pop up and trash away a "middle" commit in my master branch. How can I do it?](https://stackoverflow.com/questions/5757187/i-need-to-pop-up-and-trash-away-a-middle-commit-in-my-master-branch-how-can-i) – Karol Dowbecki Nov 21 '18 at 22:31
  • If you have the permission on the server you can force-push an older commit. However you must coordinate this with all other developers pulling from that branch and be careful not to delete anything. – eckes Nov 21 '18 at 22:59

2 Answers2

0

G. , In my opinion is you can use 'git log' command and check previous commits on your branch. Then you can copy the commit head id and roll back the previous version(the version before all these commit) using 'git reset --hard commitHeadId'. Then you can ignore the previous changes and add only third commit changes using local history or compare with branch and then commit and push.

JohnC
  • 19
  • 3
0

I managed to solve this without losing any files. First on production server, in branch which was fine I run:

git push origin --force

This overwritten my origin with the branch which had the "good" files and I needed.

Then in my development server I run:

git checkout master

to switch to master branch and then I run:

git pull

to pull all the new files from origin. This gave me in development what I needed. A fresh start without losing the other "test" branches.

Then I went back to production server to fix the local master branch also. I run

git checkout master

git pull

These gave me also a new "fixed" master branch like it was before.

Now I have both servers which are identical in git master branch and I can continue the work with new branches in development server,merge them to remote origin, so I can pull them in production server master branch.

Community
  • 1
  • 1
G. G.
  • 279
  • 1
  • 4
  • 14