简体   繁体   中英

Git reset origin/master

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. , 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM