Git reset origin/master











up vote
0
down vote

favorite












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?










share|improve this question
























  • Possible duplicate of I need to pop up and trash away a "middle" commit in my master branch. How can I do it?
    – Karol Dowbecki
    Nov 21 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 at 22:59















up vote
0
down vote

favorite












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?










share|improve this question
























  • Possible duplicate of I need to pop up and trash away a "middle" commit in my master branch. How can I do it?
    – Karol Dowbecki
    Nov 21 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 at 22:59













up vote
0
down vote

favorite









up vote
0
down vote

favorite











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?










share|improve this question















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?







git ubuntu






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 21:34

























asked Nov 21 at 22:22









G. G.

729




729












  • Possible duplicate of I need to pop up and trash away a "middle" commit in my master branch. How can I do it?
    – Karol Dowbecki
    Nov 21 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 at 22:59


















  • Possible duplicate of I need to pop up and trash away a "middle" commit in my master branch. How can I do it?
    – Karol Dowbecki
    Nov 21 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 at 22:59
















Possible duplicate of I need to pop up and trash away a "middle" commit in my master branch. How can I do it?
– Karol Dowbecki
Nov 21 at 22:31




Possible duplicate of I need to pop up and trash away a "middle" commit in my master branch. How can I do it?
– Karol Dowbecki
Nov 21 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 at 22:59




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 at 22:59












2 Answers
2






active

oldest

votes

















up vote
0
down vote













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.






share|improve this answer





















  • I have messed my git and I am stucked now. I don't know what to do
    – G. G.
    Nov 22 at 21:28


















up vote
0
down vote



accepted










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.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421269%2fgit-reset-origin-master%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    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.






    share|improve this answer





















    • I have messed my git and I am stucked now. I don't know what to do
      – G. G.
      Nov 22 at 21:28















    up vote
    0
    down vote













    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.






    share|improve this answer





















    • I have messed my git and I am stucked now. I don't know what to do
      – G. G.
      Nov 22 at 21:28













    up vote
    0
    down vote










    up vote
    0
    down vote









    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.






    share|improve this answer












    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 22 at 18:38









    JohnC

    42




    42












    • I have messed my git and I am stucked now. I don't know what to do
      – G. G.
      Nov 22 at 21:28


















    • I have messed my git and I am stucked now. I don't know what to do
      – G. G.
      Nov 22 at 21:28
















    I have messed my git and I am stucked now. I don't know what to do
    – G. G.
    Nov 22 at 21:28




    I have messed my git and I am stucked now. I don't know what to do
    – G. G.
    Nov 22 at 21:28












    up vote
    0
    down vote



    accepted










    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.






    share|improve this answer

























      up vote
      0
      down vote



      accepted










      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.






      share|improve this answer























        up vote
        0
        down vote



        accepted







        up vote
        0
        down vote



        accepted






        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.






        share|improve this answer












        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 at 13:39









        G. G.

        729




        729






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53421269%2fgit-reset-origin-master%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Catalogne

            Violoncelliste

            Héron pourpré