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?
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
add a comment |
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
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
add a comment |
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
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
git git-add
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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
Thanks that is what I really needed!
– Mazeryt
2 days ago
add a comment |
I would suggest the following:
Use git stash
(https://www.git-scm.com/docs/git-stash):
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
)- Change
FileA
accordingly git add -p -- FileA
Stage your new changes - You have now your first commit readygit stash pop
orgit stash apply
(wheter you want to keep your changes in the stash or not)- You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
Thanks that is what I really needed!
– Mazeryt
2 days ago
add a comment |
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
Thanks that is what I really needed!
– Mazeryt
2 days ago
add a comment |
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
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
answered Mar 6 at 14:26
Jan KrügerJan Krüger
13k14446
13k14446
Thanks that is what I really needed!
– Mazeryt
2 days ago
add a comment |
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
add a comment |
I would suggest the following:
Use git stash
(https://www.git-scm.com/docs/git-stash):
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
)- Change
FileA
accordingly git add -p -- FileA
Stage your new changes - You have now your first commit readygit stash pop
orgit stash apply
(wheter you want to keep your changes in the stash or not)- You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)
add a comment |
I would suggest the following:
Use git stash
(https://www.git-scm.com/docs/git-stash):
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
)- Change
FileA
accordingly git add -p -- FileA
Stage your new changes - You have now your first commit readygit stash pop
orgit stash apply
(wheter you want to keep your changes in the stash or not)- You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)
add a comment |
I would suggest the following:
Use git stash
(https://www.git-scm.com/docs/git-stash):
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
)- Change
FileA
accordingly git add -p -- FileA
Stage your new changes - You have now your first commit readygit stash pop
orgit stash apply
(wheter you want to keep your changes in the stash or not)- You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)
I would suggest the following:
Use git stash
(https://www.git-scm.com/docs/git-stash):
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
)- Change
FileA
accordingly git add -p -- FileA
Stage your new changes - You have now your first commit readygit stash pop
orgit stash apply
(wheter you want to keep your changes in the stash or not)- You have now your second commit almost ready in the working tree (make necessary changes, stage, commit, ...)
edited Mar 6 at 15:34
answered Mar 6 at 15:23
kapsikapsi
637817
637817
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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