Can I prevent git stash pop/apply if I have any file changes?What's an easy way to detect modified files in a Git workspace?Actually undo git stash popView the change history of a file using Git versioningShowing which files have changed between two revisionsHow to stop tracking and ignore changes to a file in Git?Ignore files that have already been committed to a Git repositoryHow do I make Git ignore file mode (chmod) changes?How can I delete a file from git repo?Stash only one file out of multiple files that have changed before git 2.13How can I git stash a specific file?How can I delete all of my Git stashes at once?Difference between git stash pop and git stash apply
Do Australia and New Zealand have a travel ban on Somalis (like Wikipedia says)?
Evaluate the limit the following series
Simplest instruction set that has an c++/C compiler to write an emulator for?
Is encryption still applied if you ignore the SSL certificate warning for self-signed certs?
How to not confuse readers with simultaneous events?
How slow ( not zero) can a car engine run without hurting engine and saving on fuel
Why teach C using scanf without talking about command line arguments?
What is the mistake in this solution?
Do pedestrians imitate automotive traffic?
I have found a mistake on someone's code published online: what is the protocol?
Making a Dataset that emulates `ls -tlra`?
Are there any satellites in geosynchronous but not geostationary orbits?
"Je suis petite, moi?", purpose of the "moi"?
What is this green alien supposed to be on the American covers of the "Hitchhiker's Guide to the Galaxy"?
Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?
Inscriptio Labyrinthica
Suggestions for how to track down the source of this force:source:push error?
Legendre Polynomial Integral over half space
Brute-force the switchboard
Why does a tetrahedral molecule like methane have a dipole moment of zero?
Integration using partial fraction is wrong
Was demon possession only a New Testament phenomenon?
Inside Out and Back to Front
How important are the Author's mood and feelings for writing a story?
Can I prevent git stash pop/apply if I have any file changes?
What's an easy way to detect modified files in a Git workspace?Actually undo git stash popView the change history of a file using Git versioningShowing which files have changed between two revisionsHow to stop tracking and ignore changes to a file in Git?Ignore files that have already been committed to a Git repositoryHow do I make Git ignore file mode (chmod) changes?How can I delete a file from git repo?Stash only one file out of multiple files that have changed before git 2.13How can I git stash a specific file?How can I delete all of my Git stashes at once?Difference between git stash pop and git stash apply
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I broke my own rule of having more than one item in my git stash stack, and I git stash pop
ed two of them instead of one.
That means I had two sets of changes, with no conflicts, now sat as untracked changes that I can't separate easily1.
So is there a way to make stash pop/apply interactive, and check I have no tracked or untracked changes before continuing?
1 Had there been conflicts I could have just use reset as in Actually undo git stash pop
git git-stash
add a comment |
I broke my own rule of having more than one item in my git stash stack, and I git stash pop
ed two of them instead of one.
That means I had two sets of changes, with no conflicts, now sat as untracked changes that I can't separate easily1.
So is there a way to make stash pop/apply interactive, and check I have no tracked or untracked changes before continuing?
1 Had there been conflicts I could have just use reset as in Actually undo git stash pop
git git-stash
Someone said me a good advice, rungit status
before every single git command which has an effect on your repository.
– Morteza Ziyae
Mar 26 at 19:19
@MortezaZiaeemehr the mistake actually happened as I thought the previous command was `npm run test, and ended up popping twice. Thanks for the advice though
– Pureferret
Mar 26 at 19:23
add a comment |
I broke my own rule of having more than one item in my git stash stack, and I git stash pop
ed two of them instead of one.
That means I had two sets of changes, with no conflicts, now sat as untracked changes that I can't separate easily1.
So is there a way to make stash pop/apply interactive, and check I have no tracked or untracked changes before continuing?
1 Had there been conflicts I could have just use reset as in Actually undo git stash pop
git git-stash
I broke my own rule of having more than one item in my git stash stack, and I git stash pop
ed two of them instead of one.
That means I had two sets of changes, with no conflicts, now sat as untracked changes that I can't separate easily1.
So is there a way to make stash pop/apply interactive, and check I have no tracked or untracked changes before continuing?
1 Had there been conflicts I could have just use reset as in Actually undo git stash pop
git git-stash
git git-stash
edited Mar 26 at 11:52
Pureferret
asked Mar 26 at 11:31
PureferretPureferret
3,4209 gold badges55 silver badges112 bronze badges
3,4209 gold badges55 silver badges112 bronze badges
Someone said me a good advice, rungit status
before every single git command which has an effect on your repository.
– Morteza Ziyae
Mar 26 at 19:19
@MortezaZiaeemehr the mistake actually happened as I thought the previous command was `npm run test, and ended up popping twice. Thanks for the advice though
– Pureferret
Mar 26 at 19:23
add a comment |
Someone said me a good advice, rungit status
before every single git command which has an effect on your repository.
– Morteza Ziyae
Mar 26 at 19:19
@MortezaZiaeemehr the mistake actually happened as I thought the previous command was `npm run test, and ended up popping twice. Thanks for the advice though
– Pureferret
Mar 26 at 19:23
Someone said me a good advice, run
git status
before every single git command which has an effect on your repository.– Morteza Ziyae
Mar 26 at 19:19
Someone said me a good advice, run
git status
before every single git command which has an effect on your repository.– Morteza Ziyae
Mar 26 at 19:19
@MortezaZiaeemehr the mistake actually happened as I thought the previous command was `npm run test, and ended up popping twice. Thanks for the advice though
– Pureferret
Mar 26 at 19:23
@MortezaZiaeemehr the mistake actually happened as I thought the previous command was `npm run test, and ended up popping twice. Thanks for the advice though
– Pureferret
Mar 26 at 19:23
add a comment |
1 Answer
1
active
oldest
votes
You can create an alias for git stash pop or apply that checks for differences from HEAD.
[alias]
pop = !"f() ; f "
apply = !"f() git diff-index --quiet HEAD && git stash apply "$@"; ; f"
Prefixing with !
, and wraping them in a function call f() ... ; f "
, allows passing arguments to git stash pop
and git stash apply
.
The command git diff-index --quiet HEAD
will return 0 or 1 depending on whether there are local changes, then the &&
and ||
shortcuts will either continue with the git stash pop/apply, or output an error message.
Wrapping the first part, which uses the &&
shortcut, in braces (so it's a && b; || c
) prevents the error message which uses the ||
shortcut firing when the pop or apply fails.
Then you can use git pop
to safely run git stash pop
without interfering with other changes.
As much as I don't like a setting where you idiotproof your environment in order to allow yourself consequence-free careless behaviour (pop/apply on a dirty tree) which could come bite you back one day when you switch to another environment without your aliases, ....I must admit this is clever and seems to work well. Well done.
– RomainValeri
Mar 26 at 14:28
@RomainValeri I don't like it either, but I consider git stash to both be too useful and too dangerous not to make it easier to use. Also bear in mind thatgit pop
!==git stash pop
, hopefully avoiding issues when I change environment
– Pureferret
Mar 26 at 14:29
You might want to tweak these slightly to pass arguments as well, so that you cangit pop --index
if you intended that.
– torek
Mar 26 at 16:07
1
@Pureferret: I'd define and then use a shell function just for sanity (pop = !'f() git ... ;; f'
), if doing this. The whole thing is a little painful, so be sure you keep anything you have working before you head down this path. :-)
– torek
Mar 26 at 16:57
1
Just a note that the&&
and||
in this case can have a weird effect if the first command succeeds and the second fails—it will print your error message. Typicallya && b || c
works though.
– D. Ben Knoble
Mar 26 at 17:08
|
show 3 more comments
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%2f55356101%2fcan-i-prevent-git-stash-pop-apply-if-i-have-any-file-changes%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create an alias for git stash pop or apply that checks for differences from HEAD.
[alias]
pop = !"f() ; f "
apply = !"f() git diff-index --quiet HEAD && git stash apply "$@"; ; f"
Prefixing with !
, and wraping them in a function call f() ... ; f "
, allows passing arguments to git stash pop
and git stash apply
.
The command git diff-index --quiet HEAD
will return 0 or 1 depending on whether there are local changes, then the &&
and ||
shortcuts will either continue with the git stash pop/apply, or output an error message.
Wrapping the first part, which uses the &&
shortcut, in braces (so it's a && b; || c
) prevents the error message which uses the ||
shortcut firing when the pop or apply fails.
Then you can use git pop
to safely run git stash pop
without interfering with other changes.
As much as I don't like a setting where you idiotproof your environment in order to allow yourself consequence-free careless behaviour (pop/apply on a dirty tree) which could come bite you back one day when you switch to another environment without your aliases, ....I must admit this is clever and seems to work well. Well done.
– RomainValeri
Mar 26 at 14:28
@RomainValeri I don't like it either, but I consider git stash to both be too useful and too dangerous not to make it easier to use. Also bear in mind thatgit pop
!==git stash pop
, hopefully avoiding issues when I change environment
– Pureferret
Mar 26 at 14:29
You might want to tweak these slightly to pass arguments as well, so that you cangit pop --index
if you intended that.
– torek
Mar 26 at 16:07
1
@Pureferret: I'd define and then use a shell function just for sanity (pop = !'f() git ... ;; f'
), if doing this. The whole thing is a little painful, so be sure you keep anything you have working before you head down this path. :-)
– torek
Mar 26 at 16:57
1
Just a note that the&&
and||
in this case can have a weird effect if the first command succeeds and the second fails—it will print your error message. Typicallya && b || c
works though.
– D. Ben Knoble
Mar 26 at 17:08
|
show 3 more comments
You can create an alias for git stash pop or apply that checks for differences from HEAD.
[alias]
pop = !"f() ; f "
apply = !"f() git diff-index --quiet HEAD && git stash apply "$@"; ; f"
Prefixing with !
, and wraping them in a function call f() ... ; f "
, allows passing arguments to git stash pop
and git stash apply
.
The command git diff-index --quiet HEAD
will return 0 or 1 depending on whether there are local changes, then the &&
and ||
shortcuts will either continue with the git stash pop/apply, or output an error message.
Wrapping the first part, which uses the &&
shortcut, in braces (so it's a && b; || c
) prevents the error message which uses the ||
shortcut firing when the pop or apply fails.
Then you can use git pop
to safely run git stash pop
without interfering with other changes.
As much as I don't like a setting where you idiotproof your environment in order to allow yourself consequence-free careless behaviour (pop/apply on a dirty tree) which could come bite you back one day when you switch to another environment without your aliases, ....I must admit this is clever and seems to work well. Well done.
– RomainValeri
Mar 26 at 14:28
@RomainValeri I don't like it either, but I consider git stash to both be too useful and too dangerous not to make it easier to use. Also bear in mind thatgit pop
!==git stash pop
, hopefully avoiding issues when I change environment
– Pureferret
Mar 26 at 14:29
You might want to tweak these slightly to pass arguments as well, so that you cangit pop --index
if you intended that.
– torek
Mar 26 at 16:07
1
@Pureferret: I'd define and then use a shell function just for sanity (pop = !'f() git ... ;; f'
), if doing this. The whole thing is a little painful, so be sure you keep anything you have working before you head down this path. :-)
– torek
Mar 26 at 16:57
1
Just a note that the&&
and||
in this case can have a weird effect if the first command succeeds and the second fails—it will print your error message. Typicallya && b || c
works though.
– D. Ben Knoble
Mar 26 at 17:08
|
show 3 more comments
You can create an alias for git stash pop or apply that checks for differences from HEAD.
[alias]
pop = !"f() ; f "
apply = !"f() git diff-index --quiet HEAD && git stash apply "$@"; ; f"
Prefixing with !
, and wraping them in a function call f() ... ; f "
, allows passing arguments to git stash pop
and git stash apply
.
The command git diff-index --quiet HEAD
will return 0 or 1 depending on whether there are local changes, then the &&
and ||
shortcuts will either continue with the git stash pop/apply, or output an error message.
Wrapping the first part, which uses the &&
shortcut, in braces (so it's a && b; || c
) prevents the error message which uses the ||
shortcut firing when the pop or apply fails.
Then you can use git pop
to safely run git stash pop
without interfering with other changes.
You can create an alias for git stash pop or apply that checks for differences from HEAD.
[alias]
pop = !"f() ; f "
apply = !"f() git diff-index --quiet HEAD && git stash apply "$@"; ; f"
Prefixing with !
, and wraping them in a function call f() ... ; f "
, allows passing arguments to git stash pop
and git stash apply
.
The command git diff-index --quiet HEAD
will return 0 or 1 depending on whether there are local changes, then the &&
and ||
shortcuts will either continue with the git stash pop/apply, or output an error message.
Wrapping the first part, which uses the &&
shortcut, in braces (so it's a && b; || c
) prevents the error message which uses the ||
shortcut firing when the pop or apply fails.
Then you can use git pop
to safely run git stash pop
without interfering with other changes.
edited Mar 27 at 11:38
answered Mar 26 at 14:14
PureferretPureferret
3,4209 gold badges55 silver badges112 bronze badges
3,4209 gold badges55 silver badges112 bronze badges
As much as I don't like a setting where you idiotproof your environment in order to allow yourself consequence-free careless behaviour (pop/apply on a dirty tree) which could come bite you back one day when you switch to another environment without your aliases, ....I must admit this is clever and seems to work well. Well done.
– RomainValeri
Mar 26 at 14:28
@RomainValeri I don't like it either, but I consider git stash to both be too useful and too dangerous not to make it easier to use. Also bear in mind thatgit pop
!==git stash pop
, hopefully avoiding issues when I change environment
– Pureferret
Mar 26 at 14:29
You might want to tweak these slightly to pass arguments as well, so that you cangit pop --index
if you intended that.
– torek
Mar 26 at 16:07
1
@Pureferret: I'd define and then use a shell function just for sanity (pop = !'f() git ... ;; f'
), if doing this. The whole thing is a little painful, so be sure you keep anything you have working before you head down this path. :-)
– torek
Mar 26 at 16:57
1
Just a note that the&&
and||
in this case can have a weird effect if the first command succeeds and the second fails—it will print your error message. Typicallya && b || c
works though.
– D. Ben Knoble
Mar 26 at 17:08
|
show 3 more comments
As much as I don't like a setting where you idiotproof your environment in order to allow yourself consequence-free careless behaviour (pop/apply on a dirty tree) which could come bite you back one day when you switch to another environment without your aliases, ....I must admit this is clever and seems to work well. Well done.
– RomainValeri
Mar 26 at 14:28
@RomainValeri I don't like it either, but I consider git stash to both be too useful and too dangerous not to make it easier to use. Also bear in mind thatgit pop
!==git stash pop
, hopefully avoiding issues when I change environment
– Pureferret
Mar 26 at 14:29
You might want to tweak these slightly to pass arguments as well, so that you cangit pop --index
if you intended that.
– torek
Mar 26 at 16:07
1
@Pureferret: I'd define and then use a shell function just for sanity (pop = !'f() git ... ;; f'
), if doing this. The whole thing is a little painful, so be sure you keep anything you have working before you head down this path. :-)
– torek
Mar 26 at 16:57
1
Just a note that the&&
and||
in this case can have a weird effect if the first command succeeds and the second fails—it will print your error message. Typicallya && b || c
works though.
– D. Ben Knoble
Mar 26 at 17:08
As much as I don't like a setting where you idiotproof your environment in order to allow yourself consequence-free careless behaviour (pop/apply on a dirty tree) which could come bite you back one day when you switch to another environment without your aliases, ....I must admit this is clever and seems to work well. Well done.
– RomainValeri
Mar 26 at 14:28
As much as I don't like a setting where you idiotproof your environment in order to allow yourself consequence-free careless behaviour (pop/apply on a dirty tree) which could come bite you back one day when you switch to another environment without your aliases, ....I must admit this is clever and seems to work well. Well done.
– RomainValeri
Mar 26 at 14:28
@RomainValeri I don't like it either, but I consider git stash to both be too useful and too dangerous not to make it easier to use. Also bear in mind that
git pop
!== git stash pop
, hopefully avoiding issues when I change environment– Pureferret
Mar 26 at 14:29
@RomainValeri I don't like it either, but I consider git stash to both be too useful and too dangerous not to make it easier to use. Also bear in mind that
git pop
!== git stash pop
, hopefully avoiding issues when I change environment– Pureferret
Mar 26 at 14:29
You might want to tweak these slightly to pass arguments as well, so that you can
git pop --index
if you intended that.– torek
Mar 26 at 16:07
You might want to tweak these slightly to pass arguments as well, so that you can
git pop --index
if you intended that.– torek
Mar 26 at 16:07
1
1
@Pureferret: I'd define and then use a shell function just for sanity (
pop = !'f() git ... ;; f'
), if doing this. The whole thing is a little painful, so be sure you keep anything you have working before you head down this path. :-)– torek
Mar 26 at 16:57
@Pureferret: I'd define and then use a shell function just for sanity (
pop = !'f() git ... ;; f'
), if doing this. The whole thing is a little painful, so be sure you keep anything you have working before you head down this path. :-)– torek
Mar 26 at 16:57
1
1
Just a note that the
&&
and ||
in this case can have a weird effect if the first command succeeds and the second fails—it will print your error message. Typically a && b || c
works though.– D. Ben Knoble
Mar 26 at 17:08
Just a note that the
&&
and ||
in this case can have a weird effect if the first command succeeds and the second fails—it will print your error message. Typically a && b || c
works though.– D. Ben Knoble
Mar 26 at 17:08
|
show 3 more comments
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55356101%2fcan-i-prevent-git-stash-pop-apply-if-i-have-any-file-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
Someone said me a good advice, run
git status
before every single git command which has an effect on your repository.– Morteza Ziyae
Mar 26 at 19:19
@MortezaZiaeemehr the mistake actually happened as I thought the previous command was `npm run test, and ended up popping twice. Thanks for the advice though
– Pureferret
Mar 26 at 19:23