Sourcetree - undo unpushed commits











up vote
174
down vote

favorite
41












I am using Sourcetree for Windows for a git-repository and would like to undo an unpushed commit.



Is that possible? If I do "revert commit", it creates a second commit which reverts the first commit, but I don't want the first commit to appear at all in my source control.



I could also delete my local repository and pull it again without my local commit, but maybe there's another way?










share|improve this question
























  • I have written a detailed article with screenshots. Sharing in hope that it would help: attosol.com/undo-in-git-using-sourcetree
    – Rahul Soni
    Jan 22 at 5:41















up vote
174
down vote

favorite
41












I am using Sourcetree for Windows for a git-repository and would like to undo an unpushed commit.



Is that possible? If I do "revert commit", it creates a second commit which reverts the first commit, but I don't want the first commit to appear at all in my source control.



I could also delete my local repository and pull it again without my local commit, but maybe there's another way?










share|improve this question
























  • I have written a detailed article with screenshots. Sharing in hope that it would help: attosol.com/undo-in-git-using-sourcetree
    – Rahul Soni
    Jan 22 at 5:41













up vote
174
down vote

favorite
41









up vote
174
down vote

favorite
41






41





I am using Sourcetree for Windows for a git-repository and would like to undo an unpushed commit.



Is that possible? If I do "revert commit", it creates a second commit which reverts the first commit, but I don't want the first commit to appear at all in my source control.



I could also delete my local repository and pull it again without my local commit, but maybe there's another way?










share|improve this question















I am using Sourcetree for Windows for a git-repository and would like to undo an unpushed commit.



Is that possible? If I do "revert commit", it creates a second commit which reverts the first commit, but I don't want the first commit to appear at all in my source control.



I could also delete my local repository and pull it again without my local commit, but maybe there's another way?







atlassian-sourcetree datasourcecontrol






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 at 23:03









shim

3,77764477




3,77764477










asked May 26 '14 at 7:56









deimos1988

1,98173051




1,98173051












  • I have written a detailed article with screenshots. Sharing in hope that it would help: attosol.com/undo-in-git-using-sourcetree
    – Rahul Soni
    Jan 22 at 5:41


















  • I have written a detailed article with screenshots. Sharing in hope that it would help: attosol.com/undo-in-git-using-sourcetree
    – Rahul Soni
    Jan 22 at 5:41
















I have written a detailed article with screenshots. Sharing in hope that it would help: attosol.com/undo-in-git-using-sourcetree
– Rahul Soni
Jan 22 at 5:41




I have written a detailed article with screenshots. Sharing in hope that it would help: attosol.com/undo-in-git-using-sourcetree
– Rahul Soni
Jan 22 at 5:41












3 Answers
3






active

oldest

votes

















up vote
292
down vote














  1. Right click on the commit you like to reset to (not the one you like to delete!)

  2. Select "Reset master to this commit"

  3. Select "Soft" reset.


A soft reset will keep your local changes.



Source: https://answers.atlassian.com/questions/153791/how-should-i-remove-push-commit-from-sourcetree



Edit



About git revert: This command creates a new commit which will undo other commits. E.g. if you have a commit which adds a new file, git revert could be used to make a commit which will delete the new file.



About applying a soft reset: Assume you have the commits A to E (A---B---C---D---E) and you like to delete the last commit (E). Then you can do a soft reset to commit D. With a soft reset commit E will be deleted from git but the local changes will be kept. There are more examples in the git reset documentation.






share|improve this answer



















  • 31




    Or if you're working on a branch - "Reset current branch to this commit"
    – Tom Auger
    Aug 12 '15 at 13:26






  • 4




    I so much don't understand these UI explanations... Reset current branch to this commit so much doesn't sound like it will delete the commit. And it ended up doing what you would expect more. It reset my working copy to the commit, instead of deleting it.
    – MrFox
    Nov 24 '15 at 13:32












  • I agree with @MrFox. After I did this the commit I don't want is still shown in the tree.
    – Timmmm
    Jan 11 '16 at 11:09










  • @Timmmm: Does the new explanation help?
    – nightlyop
    Jan 11 '16 at 12:29










  • Actually I realised that I had already pushed my commit to github. I found an article that explains how to "rewrite history" but it seems like it is more trouble than it is worth!
    – Timmmm
    Jan 11 '16 at 15:40


















up vote
32
down vote













If you select the log entry to which you want to revert to then you can click on "Reset to this commit". Only use this option if you didn't push the reverse commit changes. If you're worried about losing the changes then you can use the soft mode which will leave a set of uncommitted changes (what you just changed). Using the mixed resets the working copy but keeps those changes, and a hard will just get rid of the changes entirely. Here's some screenshots:



enter image description here






share|improve this answer



















  • 3




    If you still see a icon showing a Push is available from your previous commit (Which you just wiped out), pull and Sourcetree seems to update the UI.
    – ChristoKiwi
    Nov 11 '16 at 4:56


















up vote
0
down vote













If You are on another branch, You need first "check to this commit" for commit you want to delete, and only then "reset current branch to this commit" choosing previous wright commit, will work.






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%2f23865335%2fsourcetree-undo-unpushed-commits%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    292
    down vote














    1. Right click on the commit you like to reset to (not the one you like to delete!)

    2. Select "Reset master to this commit"

    3. Select "Soft" reset.


    A soft reset will keep your local changes.



    Source: https://answers.atlassian.com/questions/153791/how-should-i-remove-push-commit-from-sourcetree



    Edit



    About git revert: This command creates a new commit which will undo other commits. E.g. if you have a commit which adds a new file, git revert could be used to make a commit which will delete the new file.



    About applying a soft reset: Assume you have the commits A to E (A---B---C---D---E) and you like to delete the last commit (E). Then you can do a soft reset to commit D. With a soft reset commit E will be deleted from git but the local changes will be kept. There are more examples in the git reset documentation.






    share|improve this answer



















    • 31




      Or if you're working on a branch - "Reset current branch to this commit"
      – Tom Auger
      Aug 12 '15 at 13:26






    • 4




      I so much don't understand these UI explanations... Reset current branch to this commit so much doesn't sound like it will delete the commit. And it ended up doing what you would expect more. It reset my working copy to the commit, instead of deleting it.
      – MrFox
      Nov 24 '15 at 13:32












    • I agree with @MrFox. After I did this the commit I don't want is still shown in the tree.
      – Timmmm
      Jan 11 '16 at 11:09










    • @Timmmm: Does the new explanation help?
      – nightlyop
      Jan 11 '16 at 12:29










    • Actually I realised that I had already pushed my commit to github. I found an article that explains how to "rewrite history" but it seems like it is more trouble than it is worth!
      – Timmmm
      Jan 11 '16 at 15:40















    up vote
    292
    down vote














    1. Right click on the commit you like to reset to (not the one you like to delete!)

    2. Select "Reset master to this commit"

    3. Select "Soft" reset.


    A soft reset will keep your local changes.



    Source: https://answers.atlassian.com/questions/153791/how-should-i-remove-push-commit-from-sourcetree



    Edit



    About git revert: This command creates a new commit which will undo other commits. E.g. if you have a commit which adds a new file, git revert could be used to make a commit which will delete the new file.



    About applying a soft reset: Assume you have the commits A to E (A---B---C---D---E) and you like to delete the last commit (E). Then you can do a soft reset to commit D. With a soft reset commit E will be deleted from git but the local changes will be kept. There are more examples in the git reset documentation.






    share|improve this answer



















    • 31




      Or if you're working on a branch - "Reset current branch to this commit"
      – Tom Auger
      Aug 12 '15 at 13:26






    • 4




      I so much don't understand these UI explanations... Reset current branch to this commit so much doesn't sound like it will delete the commit. And it ended up doing what you would expect more. It reset my working copy to the commit, instead of deleting it.
      – MrFox
      Nov 24 '15 at 13:32












    • I agree with @MrFox. After I did this the commit I don't want is still shown in the tree.
      – Timmmm
      Jan 11 '16 at 11:09










    • @Timmmm: Does the new explanation help?
      – nightlyop
      Jan 11 '16 at 12:29










    • Actually I realised that I had already pushed my commit to github. I found an article that explains how to "rewrite history" but it seems like it is more trouble than it is worth!
      – Timmmm
      Jan 11 '16 at 15:40













    up vote
    292
    down vote










    up vote
    292
    down vote










    1. Right click on the commit you like to reset to (not the one you like to delete!)

    2. Select "Reset master to this commit"

    3. Select "Soft" reset.


    A soft reset will keep your local changes.



    Source: https://answers.atlassian.com/questions/153791/how-should-i-remove-push-commit-from-sourcetree



    Edit



    About git revert: This command creates a new commit which will undo other commits. E.g. if you have a commit which adds a new file, git revert could be used to make a commit which will delete the new file.



    About applying a soft reset: Assume you have the commits A to E (A---B---C---D---E) and you like to delete the last commit (E). Then you can do a soft reset to commit D. With a soft reset commit E will be deleted from git but the local changes will be kept. There are more examples in the git reset documentation.






    share|improve this answer















    1. Right click on the commit you like to reset to (not the one you like to delete!)

    2. Select "Reset master to this commit"

    3. Select "Soft" reset.


    A soft reset will keep your local changes.



    Source: https://answers.atlassian.com/questions/153791/how-should-i-remove-push-commit-from-sourcetree



    Edit



    About git revert: This command creates a new commit which will undo other commits. E.g. if you have a commit which adds a new file, git revert could be used to make a commit which will delete the new file.



    About applying a soft reset: Assume you have the commits A to E (A---B---C---D---E) and you like to delete the last commit (E). Then you can do a soft reset to commit D. With a soft reset commit E will be deleted from git but the local changes will be kept. There are more examples in the git reset documentation.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 11 '16 at 12:27

























    answered Oct 15 '14 at 9:53









    nightlyop

    4,98131734




    4,98131734








    • 31




      Or if you're working on a branch - "Reset current branch to this commit"
      – Tom Auger
      Aug 12 '15 at 13:26






    • 4




      I so much don't understand these UI explanations... Reset current branch to this commit so much doesn't sound like it will delete the commit. And it ended up doing what you would expect more. It reset my working copy to the commit, instead of deleting it.
      – MrFox
      Nov 24 '15 at 13:32












    • I agree with @MrFox. After I did this the commit I don't want is still shown in the tree.
      – Timmmm
      Jan 11 '16 at 11:09










    • @Timmmm: Does the new explanation help?
      – nightlyop
      Jan 11 '16 at 12:29










    • Actually I realised that I had already pushed my commit to github. I found an article that explains how to "rewrite history" but it seems like it is more trouble than it is worth!
      – Timmmm
      Jan 11 '16 at 15:40














    • 31




      Or if you're working on a branch - "Reset current branch to this commit"
      – Tom Auger
      Aug 12 '15 at 13:26






    • 4




      I so much don't understand these UI explanations... Reset current branch to this commit so much doesn't sound like it will delete the commit. And it ended up doing what you would expect more. It reset my working copy to the commit, instead of deleting it.
      – MrFox
      Nov 24 '15 at 13:32












    • I agree with @MrFox. After I did this the commit I don't want is still shown in the tree.
      – Timmmm
      Jan 11 '16 at 11:09










    • @Timmmm: Does the new explanation help?
      – nightlyop
      Jan 11 '16 at 12:29










    • Actually I realised that I had already pushed my commit to github. I found an article that explains how to "rewrite history" but it seems like it is more trouble than it is worth!
      – Timmmm
      Jan 11 '16 at 15:40








    31




    31




    Or if you're working on a branch - "Reset current branch to this commit"
    – Tom Auger
    Aug 12 '15 at 13:26




    Or if you're working on a branch - "Reset current branch to this commit"
    – Tom Auger
    Aug 12 '15 at 13:26




    4




    4




    I so much don't understand these UI explanations... Reset current branch to this commit so much doesn't sound like it will delete the commit. And it ended up doing what you would expect more. It reset my working copy to the commit, instead of deleting it.
    – MrFox
    Nov 24 '15 at 13:32






    I so much don't understand these UI explanations... Reset current branch to this commit so much doesn't sound like it will delete the commit. And it ended up doing what you would expect more. It reset my working copy to the commit, instead of deleting it.
    – MrFox
    Nov 24 '15 at 13:32














    I agree with @MrFox. After I did this the commit I don't want is still shown in the tree.
    – Timmmm
    Jan 11 '16 at 11:09




    I agree with @MrFox. After I did this the commit I don't want is still shown in the tree.
    – Timmmm
    Jan 11 '16 at 11:09












    @Timmmm: Does the new explanation help?
    – nightlyop
    Jan 11 '16 at 12:29




    @Timmmm: Does the new explanation help?
    – nightlyop
    Jan 11 '16 at 12:29












    Actually I realised that I had already pushed my commit to github. I found an article that explains how to "rewrite history" but it seems like it is more trouble than it is worth!
    – Timmmm
    Jan 11 '16 at 15:40




    Actually I realised that I had already pushed my commit to github. I found an article that explains how to "rewrite history" but it seems like it is more trouble than it is worth!
    – Timmmm
    Jan 11 '16 at 15:40












    up vote
    32
    down vote













    If you select the log entry to which you want to revert to then you can click on "Reset to this commit". Only use this option if you didn't push the reverse commit changes. If you're worried about losing the changes then you can use the soft mode which will leave a set of uncommitted changes (what you just changed). Using the mixed resets the working copy but keeps those changes, and a hard will just get rid of the changes entirely. Here's some screenshots:



    enter image description here






    share|improve this answer



















    • 3




      If you still see a icon showing a Push is available from your previous commit (Which you just wiped out), pull and Sourcetree seems to update the UI.
      – ChristoKiwi
      Nov 11 '16 at 4:56















    up vote
    32
    down vote













    If you select the log entry to which you want to revert to then you can click on "Reset to this commit". Only use this option if you didn't push the reverse commit changes. If you're worried about losing the changes then you can use the soft mode which will leave a set of uncommitted changes (what you just changed). Using the mixed resets the working copy but keeps those changes, and a hard will just get rid of the changes entirely. Here's some screenshots:



    enter image description here






    share|improve this answer



















    • 3




      If you still see a icon showing a Push is available from your previous commit (Which you just wiped out), pull and Sourcetree seems to update the UI.
      – ChristoKiwi
      Nov 11 '16 at 4:56













    up vote
    32
    down vote










    up vote
    32
    down vote









    If you select the log entry to which you want to revert to then you can click on "Reset to this commit". Only use this option if you didn't push the reverse commit changes. If you're worried about losing the changes then you can use the soft mode which will leave a set of uncommitted changes (what you just changed). Using the mixed resets the working copy but keeps those changes, and a hard will just get rid of the changes entirely. Here's some screenshots:



    enter image description here






    share|improve this answer














    If you select the log entry to which you want to revert to then you can click on "Reset to this commit". Only use this option if you didn't push the reverse commit changes. If you're worried about losing the changes then you can use the soft mode which will leave a set of uncommitted changes (what you just changed). Using the mixed resets the working copy but keeps those changes, and a hard will just get rid of the changes entirely. Here's some screenshots:



    enter image description here







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Apr 14 '16 at 9:42

























    answered Apr 14 '16 at 9:37









    Muhammad Awais

    1,80512320




    1,80512320








    • 3




      If you still see a icon showing a Push is available from your previous commit (Which you just wiped out), pull and Sourcetree seems to update the UI.
      – ChristoKiwi
      Nov 11 '16 at 4:56














    • 3




      If you still see a icon showing a Push is available from your previous commit (Which you just wiped out), pull and Sourcetree seems to update the UI.
      – ChristoKiwi
      Nov 11 '16 at 4:56








    3




    3




    If you still see a icon showing a Push is available from your previous commit (Which you just wiped out), pull and Sourcetree seems to update the UI.
    – ChristoKiwi
    Nov 11 '16 at 4:56




    If you still see a icon showing a Push is available from your previous commit (Which you just wiped out), pull and Sourcetree seems to update the UI.
    – ChristoKiwi
    Nov 11 '16 at 4:56










    up vote
    0
    down vote













    If You are on another branch, You need first "check to this commit" for commit you want to delete, and only then "reset current branch to this commit" choosing previous wright commit, will work.






    share|improve this answer

























      up vote
      0
      down vote













      If You are on another branch, You need first "check to this commit" for commit you want to delete, and only then "reset current branch to this commit" choosing previous wright commit, will work.






      share|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        If You are on another branch, You need first "check to this commit" for commit you want to delete, and only then "reset current branch to this commit" choosing previous wright commit, will work.






        share|improve this answer












        If You are on another branch, You need first "check to this commit" for commit you want to delete, and only then "reset current branch to this commit" choosing previous wright commit, will work.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 29 '17 at 6:59









        pomaranga

        11




        11






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f23865335%2fsourcetree-undo-unpushed-commits%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

            To store a contact into the json file from server.js file using a class in NodeJS

            Redirect URL with Chrome Remote Debugging Android Devices

            Dieringhausen