git move part of changes from “to be comitted” to local changes2019 Community Moderator ElectionHow do I discard unstaged changes in Git?How to remove local (untracked) files from the current Git working tree?Commit only part of a file in GitHow do I force “git pull” to overwrite local files?Remove a file from a Git repository without deleting it from the local filesystemMove the most recent commit(s) to a new branch with GitHow do I delete a Git branch both locally and remotely?How do I push a new local branch to a remote Git repository and track it too?How can I reconcile detached HEAD with master/origin?How do I rename a local Git branch?

Is divide-by-zero a security vulnerability?

I am the person who abides by rules, but breaks the rules. Who am I?

Would those living in a "perfect society" not understand satire

One circle's diameter is different from others within a series of circles

What is this tube in a jet engine's air intake?

What would be the most expensive material to an intergalactic society?

Will expression retain the same definition if particle is changed?

Does an unused member variable take up memory?

Origin of the word “pushka”

ESPP--any reason not to go all in?

Create chunks from an array

Movie: boy escapes the real world and goes to a fantasy world with big furry trolls

If sound is a longitudinal wave, why can we hear it if our ears aren't aligned with the propagation direction?

Has a sovereign Communist government ever run, and conceded loss, on a fair election?

What should I do when a paper is published similar to my PhD thesis without citation?

How do spaceships determine each other's mass in space?

Did Amazon pay $0 in taxes last year?

Use Mercury as quenching liquid for swords?

How can a demon take control of a human body during REM sleep?

How to write a chaotic neutral protagonist and prevent my readers from thinking they are evil?

Can one live in the U.S. and not use a credit card?

How should I solve this integral with changing parameters?

What sort of fish is this

Should we avoid writing fiction about historical events without extensive research?



git move part of changes from “to be comitted” to local changes



2019 Community Moderator ElectionHow do I discard unstaged changes in Git?How to remove local (untracked) files from the current Git working tree?Commit only part of a file in GitHow do I force “git pull” to overwrite local files?Remove a file from a Git repository without deleting it from the local filesystemMove the most recent commit(s) to a new branch with GitHow do I delete a Git branch both locally and remotely?How do I push a new local branch to a remote Git repository and track it too?How can I reconcile detached HEAD with master/origin?How do I rename a local Git branch?










1















I have a file that I modified with 2 set of changes: formatting and adding new feature.



I need to turn them into 2 commits.

- Formatting changes

- New Feature A.



Now I used git add --patch and staged all the formatting stuff. So I have:



Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: FileA <-- formatting changes

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: FileA <-- Feature A


Now before commit, I realized that I put one function (few lines) to the formatting changes (it should land inside Feature changes).



Can I somehow edit now changes to be committed? The file is significant and I don't want to go over again with git add --patch.



The only solution that I can think of to omit running through git add --patch is to commit current changes and then remove these lines from the commit itself.



Is any other way to do that?










share|improve this question



















  • 1





    I'd be curious to know what was the reason behind the downvote, since I found it both useful and clearly asked. Not that there could be no reasons to downvote, of course, I was just wondering.

    – RomainValeri
    Mar 6 at 14:46















1















I have a file that I modified with 2 set of changes: formatting and adding new feature.



I need to turn them into 2 commits.

- Formatting changes

- New Feature A.



Now I used git add --patch and staged all the formatting stuff. So I have:



Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: FileA <-- formatting changes

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: FileA <-- Feature A


Now before commit, I realized that I put one function (few lines) to the formatting changes (it should land inside Feature changes).



Can I somehow edit now changes to be committed? The file is significant and I don't want to go over again with git add --patch.



The only solution that I can think of to omit running through git add --patch is to commit current changes and then remove these lines from the commit itself.



Is any other way to do that?










share|improve this question



















  • 1





    I'd be curious to know what was the reason behind the downvote, since I found it both useful and clearly asked. Not that there could be no reasons to downvote, of course, I was just wondering.

    – RomainValeri
    Mar 6 at 14:46













1












1








1








I have a file that I modified with 2 set of changes: formatting and adding new feature.



I need to turn them into 2 commits.

- Formatting changes

- New Feature A.



Now I used git add --patch and staged all the formatting stuff. So I have:



Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: FileA <-- formatting changes

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: FileA <-- Feature A


Now before commit, I realized that I put one function (few lines) to the formatting changes (it should land inside Feature changes).



Can I somehow edit now changes to be committed? The file is significant and I don't want to go over again with git add --patch.



The only solution that I can think of to omit running through git add --patch is to commit current changes and then remove these lines from the commit itself.



Is any other way to do that?










share|improve this question
















I have a file that I modified with 2 set of changes: formatting and adding new feature.



I need to turn them into 2 commits.

- Formatting changes

- New Feature A.



Now I used git add --patch and staged all the formatting stuff. So I have:



Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified: FileA <-- formatting changes

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified: FileA <-- Feature A


Now before commit, I realized that I put one function (few lines) to the formatting changes (it should land inside Feature changes).



Can I somehow edit now changes to be committed? The file is significant and I don't want to go over again with git add --patch.



The only solution that I can think of to omit running through git add --patch is to commit current changes and then remove these lines from the commit itself.



Is any other way to do that?







git git-add






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 6 at 14:49







Mazeryt

















asked Mar 6 at 13:53









MazerytMazeryt

40011027




40011027







  • 1





    I'd be curious to know what was the reason behind the downvote, since I found it both useful and clearly asked. Not that there could be no reasons to downvote, of course, I was just wondering.

    – RomainValeri
    Mar 6 at 14:46












  • 1





    I'd be curious to know what was the reason behind the downvote, since I found it both useful and clearly asked. Not that there could be no reasons to downvote, of course, I was just wondering.

    – RomainValeri
    Mar 6 at 14:46







1




1





I'd be curious to know what was the reason behind the downvote, since I found it both useful and clearly asked. Not that there could be no reasons to downvote, of course, I was just wondering.

– RomainValeri
Mar 6 at 14:46





I'd be curious to know what was the reason behind the downvote, since I found it both useful and clearly asked. Not that there could be no reasons to downvote, of course, I was just wondering.

– RomainValeri
Mar 6 at 14:46












2 Answers
2






active

oldest

votes


















4














There's also git reset --patch which is the reverse of git add --patch.



For a single small change, using git gui can be easier, though - you can interactively stage/unstage individual lines of code just by right-clicking them. Some of the other Git GUIs might have similar features.



Failing that, here's a slightly ugly way to do this without going through everything again:



  • git diff --cached >temp.diff

  • git reset

  • Edit temp.diff and remove the hunk with the change you didn't want to commit

  • git apply --cached --recount temp.diff

  • Commit





share|improve this answer























  • Thanks that is what I really needed!

    – Mazeryt
    2 days ago


















0














I would suggest the following:

Use git stash (https://www.git-scm.com/docs/git-stash):




  1. git stash --keep-index

    This pushes your current working tree on the stash and keeps your staged changes

    Be aware of untracked files. By default untracked files don't get pushed on the stash! (There is another option for that: --include-untracked)

  2. Change FileA accordingly


  3. git add -p -- FileA

    Stage your new changes - You have now your first commit ready


  4. git stash pop or git stash apply (wheter you want to keep your changes in the stash or not)

  5. You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)





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',
    autoActivateHeartbeat: false,
    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%2f55024759%2fgit-move-part-of-changes-from-to-be-comitted-to-local-changes%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









    4














    There's also git reset --patch which is the reverse of git add --patch.



    For a single small change, using git gui can be easier, though - you can interactively stage/unstage individual lines of code just by right-clicking them. Some of the other Git GUIs might have similar features.



    Failing that, here's a slightly ugly way to do this without going through everything again:



    • git diff --cached >temp.diff

    • git reset

    • Edit temp.diff and remove the hunk with the change you didn't want to commit

    • git apply --cached --recount temp.diff

    • Commit





    share|improve this answer























    • Thanks that is what I really needed!

      – Mazeryt
      2 days ago















    4














    There's also git reset --patch which is the reverse of git add --patch.



    For a single small change, using git gui can be easier, though - you can interactively stage/unstage individual lines of code just by right-clicking them. Some of the other Git GUIs might have similar features.



    Failing that, here's a slightly ugly way to do this without going through everything again:



    • git diff --cached >temp.diff

    • git reset

    • Edit temp.diff and remove the hunk with the change you didn't want to commit

    • git apply --cached --recount temp.diff

    • Commit





    share|improve this answer























    • Thanks that is what I really needed!

      – Mazeryt
      2 days ago













    4












    4








    4







    There's also git reset --patch which is the reverse of git add --patch.



    For a single small change, using git gui can be easier, though - you can interactively stage/unstage individual lines of code just by right-clicking them. Some of the other Git GUIs might have similar features.



    Failing that, here's a slightly ugly way to do this without going through everything again:



    • git diff --cached >temp.diff

    • git reset

    • Edit temp.diff and remove the hunk with the change you didn't want to commit

    • git apply --cached --recount temp.diff

    • Commit





    share|improve this answer













    There's also git reset --patch which is the reverse of git add --patch.



    For a single small change, using git gui can be easier, though - you can interactively stage/unstage individual lines of code just by right-clicking them. Some of the other Git GUIs might have similar features.



    Failing that, here's a slightly ugly way to do this without going through everything again:



    • git diff --cached >temp.diff

    • git reset

    • Edit temp.diff and remove the hunk with the change you didn't want to commit

    • git apply --cached --recount temp.diff

    • Commit






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Mar 6 at 14:26









    Jan KrügerJan Krüger

    13k14446




    13k14446












    • Thanks that is what I really needed!

      – Mazeryt
      2 days ago

















    • Thanks that is what I really needed!

      – Mazeryt
      2 days ago
















    Thanks that is what I really needed!

    – Mazeryt
    2 days ago





    Thanks that is what I really needed!

    – Mazeryt
    2 days ago













    0














    I would suggest the following:

    Use git stash (https://www.git-scm.com/docs/git-stash):




    1. git stash --keep-index

      This pushes your current working tree on the stash and keeps your staged changes

      Be aware of untracked files. By default untracked files don't get pushed on the stash! (There is another option for that: --include-untracked)

    2. Change FileA accordingly


    3. git add -p -- FileA

      Stage your new changes - You have now your first commit ready


    4. git stash pop or git stash apply (wheter you want to keep your changes in the stash or not)

    5. You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)





    share|improve this answer





























      0














      I would suggest the following:

      Use git stash (https://www.git-scm.com/docs/git-stash):




      1. git stash --keep-index

        This pushes your current working tree on the stash and keeps your staged changes

        Be aware of untracked files. By default untracked files don't get pushed on the stash! (There is another option for that: --include-untracked)

      2. Change FileA accordingly


      3. git add -p -- FileA

        Stage your new changes - You have now your first commit ready


      4. git stash pop or git stash apply (wheter you want to keep your changes in the stash or not)

      5. You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)





      share|improve this answer



























        0












        0








        0







        I would suggest the following:

        Use git stash (https://www.git-scm.com/docs/git-stash):




        1. git stash --keep-index

          This pushes your current working tree on the stash and keeps your staged changes

          Be aware of untracked files. By default untracked files don't get pushed on the stash! (There is another option for that: --include-untracked)

        2. Change FileA accordingly


        3. git add -p -- FileA

          Stage your new changes - You have now your first commit ready


        4. git stash pop or git stash apply (wheter you want to keep your changes in the stash or not)

        5. You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)





        share|improve this answer















        I would suggest the following:

        Use git stash (https://www.git-scm.com/docs/git-stash):




        1. git stash --keep-index

          This pushes your current working tree on the stash and keeps your staged changes

          Be aware of untracked files. By default untracked files don't get pushed on the stash! (There is another option for that: --include-untracked)

        2. Change FileA accordingly


        3. git add -p -- FileA

          Stage your new changes - You have now your first commit ready


        4. git stash pop or git stash apply (wheter you want to keep your changes in the stash or not)

        5. You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 6 at 15:34

























        answered Mar 6 at 15:23









        kapsikapsi

        637817




        637817



























            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.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55024759%2fgit-move-part-of-changes-from-to-be-comitted-to-local-changes%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

            Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

            Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

            Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved