Git stash uncommitted files












2















I have two servers for development and production. In the development server I have a new branch merged with origin. Now I want to go to production and pull the changes.
But in production server in branch master I have modified two files which is needed only for this server.



So when I hit:




git pull




I get:



error: Your local changes to the following files would be overwritten by merge:
app/code/local/NextBits/DependentCustomOptionsImage/Block/Adminhtml/Template/Edit/Tab/Options/Option.php
app/design/adminhtml/default/default/layout/dependentcustomoptionsimage.xml
Please, commit your changes or stash them before you can merge


These are the two files I need.



How can I pull the origin and without overwriting these files?



Or how can I keep these files, pull the changes and revert them back?










share|improve this question




















  • 1





    Possible duplicate of How do I resolve git saying "Commit your changes or stash them before you can merge"?

    – phd
    Nov 21 '18 at 12:31











  • stackoverflow.com/…

    – phd
    Nov 21 '18 at 12:31











  • @phd this question you mentioned didn't help me. In fact I lost some files. The git I have is for a magento site and not all files are in origin

    – G. G.
    Nov 21 '18 at 12:37
















2















I have two servers for development and production. In the development server I have a new branch merged with origin. Now I want to go to production and pull the changes.
But in production server in branch master I have modified two files which is needed only for this server.



So when I hit:




git pull




I get:



error: Your local changes to the following files would be overwritten by merge:
app/code/local/NextBits/DependentCustomOptionsImage/Block/Adminhtml/Template/Edit/Tab/Options/Option.php
app/design/adminhtml/default/default/layout/dependentcustomoptionsimage.xml
Please, commit your changes or stash them before you can merge


These are the two files I need.



How can I pull the origin and without overwriting these files?



Or how can I keep these files, pull the changes and revert them back?










share|improve this question




















  • 1





    Possible duplicate of How do I resolve git saying "Commit your changes or stash them before you can merge"?

    – phd
    Nov 21 '18 at 12:31











  • stackoverflow.com/…

    – phd
    Nov 21 '18 at 12:31











  • @phd this question you mentioned didn't help me. In fact I lost some files. The git I have is for a magento site and not all files are in origin

    – G. G.
    Nov 21 '18 at 12:37














2












2








2








I have two servers for development and production. In the development server I have a new branch merged with origin. Now I want to go to production and pull the changes.
But in production server in branch master I have modified two files which is needed only for this server.



So when I hit:




git pull




I get:



error: Your local changes to the following files would be overwritten by merge:
app/code/local/NextBits/DependentCustomOptionsImage/Block/Adminhtml/Template/Edit/Tab/Options/Option.php
app/design/adminhtml/default/default/layout/dependentcustomoptionsimage.xml
Please, commit your changes or stash them before you can merge


These are the two files I need.



How can I pull the origin and without overwriting these files?



Or how can I keep these files, pull the changes and revert them back?










share|improve this question
















I have two servers for development and production. In the development server I have a new branch merged with origin. Now I want to go to production and pull the changes.
But in production server in branch master I have modified two files which is needed only for this server.



So when I hit:




git pull




I get:



error: Your local changes to the following files would be overwritten by merge:
app/code/local/NextBits/DependentCustomOptionsImage/Block/Adminhtml/Template/Edit/Tab/Options/Option.php
app/design/adminhtml/default/default/layout/dependentcustomoptionsimage.xml
Please, commit your changes or stash them before you can merge


These are the two files I need.



How can I pull the origin and without overwriting these files?



Or how can I keep these files, pull the changes and revert them back?







git git-pull git-stash






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 12:32









phd

23.8k52646




23.8k52646










asked Nov 21 '18 at 11:53









G. G.G. G.

729




729








  • 1





    Possible duplicate of How do I resolve git saying "Commit your changes or stash them before you can merge"?

    – phd
    Nov 21 '18 at 12:31











  • stackoverflow.com/…

    – phd
    Nov 21 '18 at 12:31











  • @phd this question you mentioned didn't help me. In fact I lost some files. The git I have is for a magento site and not all files are in origin

    – G. G.
    Nov 21 '18 at 12:37














  • 1





    Possible duplicate of How do I resolve git saying "Commit your changes or stash them before you can merge"?

    – phd
    Nov 21 '18 at 12:31











  • stackoverflow.com/…

    – phd
    Nov 21 '18 at 12:31











  • @phd this question you mentioned didn't help me. In fact I lost some files. The git I have is for a magento site and not all files are in origin

    – G. G.
    Nov 21 '18 at 12:37








1




1





Possible duplicate of How do I resolve git saying "Commit your changes or stash them before you can merge"?

– phd
Nov 21 '18 at 12:31





Possible duplicate of How do I resolve git saying "Commit your changes or stash them before you can merge"?

– phd
Nov 21 '18 at 12:31













stackoverflow.com/…

– phd
Nov 21 '18 at 12:31





stackoverflow.com/…

– phd
Nov 21 '18 at 12:31













@phd this question you mentioned didn't help me. In fact I lost some files. The git I have is for a magento site and not all files are in origin

– G. G.
Nov 21 '18 at 12:37





@phd this question you mentioned didn't help me. In fact I lost some files. The git I have is for a magento site and not all files are in origin

– G. G.
Nov 21 '18 at 12:37












1 Answer
1






active

oldest

votes


















4














There are at least three different solutions to achieve this:





  • You can commit your changes on these two files in the production server, before running git pull:



    git add -v -u
    git commit -m "Save prod config"
    git pull


    This will typically create a merge commit combining the local branch (with the commit "Save prod config") and the changes from your remote.



    If there is some conflict, you'll just need to resolve it with the help of git status, git diff, and git commit.



    For subsequent updates, it should suffice to run git pull.




  • Like the previous solution, you can commit your changes on the two production config files, but run git pull -r afterwards:



    git add -v -u
    git commit -m "Save prod config"
    git pull -r


    The -r option stands for --rebase and means that the local commit(s) specific to the production server will be rebased on top of the pulled commits.



    Subsequent updates can be performed by running git pull -r.



    The main advantage of this solution is just the ability to keep a "linear history": there is no merge commit created and the "Save prod config" commit will always be replayed at the 'end' of the history.




  • or you can use the git stash command (which may have some drawbacks in case of conflict):



    git stash
    git pull
    git stash pop







share|improve this answer


























  • after git commit -m "Save prod config" I get: Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. Why this is happening?

    – G. G.
    Nov 21 '18 at 12:32













  • @G.G. in general the message "your branch is behind... and can be fast-forwarded" is not a warning, but just an indication that "git pull" wouldn't create a merge commit because master happens to be a direct ancestor of origin/master, so "git pull" would just update the local branch by moving the local branch to the latest upstream commit. However, it seems to me this situation should not have occurred given the use case you described in your question. Maybe check you have indeed run "git add ..." and that the commit has been successfully created in the good branch.

    – ErikMD
    Nov 21 '18 at 13:12













  • Instead of git merge, you could also use git fetch and a git merge --no-ff --no-commit if you want to review changes to production before you change something...

    – Christoph
    Nov 21 '18 at 15:11













  • @ErikMD understood. But the only change I have made in this server are the files I already mentioned. Please if I fast forward the master branch will I loose anything?

    – G. G.
    Nov 21 '18 at 19:34











  • @G.G. a fast-forward merge can't cause losing files. In general, with Git you can't lose changes, provided they have been committed at some point. E.g., you can always rollback HEAD to some previous state after inspecting its history with git reflog. But you said in a previous comment you had lost changes (maybe with a git checkout -- filenames command? which is indeed a destructive one) so hopefully you've already saved (committed) the files mentioned in your post.

    – ErikMD
    Nov 21 '18 at 20:17











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%2f53411493%2fgit-stash-uncommitted-files%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









4














There are at least three different solutions to achieve this:





  • You can commit your changes on these two files in the production server, before running git pull:



    git add -v -u
    git commit -m "Save prod config"
    git pull


    This will typically create a merge commit combining the local branch (with the commit "Save prod config") and the changes from your remote.



    If there is some conflict, you'll just need to resolve it with the help of git status, git diff, and git commit.



    For subsequent updates, it should suffice to run git pull.




  • Like the previous solution, you can commit your changes on the two production config files, but run git pull -r afterwards:



    git add -v -u
    git commit -m "Save prod config"
    git pull -r


    The -r option stands for --rebase and means that the local commit(s) specific to the production server will be rebased on top of the pulled commits.



    Subsequent updates can be performed by running git pull -r.



    The main advantage of this solution is just the ability to keep a "linear history": there is no merge commit created and the "Save prod config" commit will always be replayed at the 'end' of the history.




  • or you can use the git stash command (which may have some drawbacks in case of conflict):



    git stash
    git pull
    git stash pop







share|improve this answer


























  • after git commit -m "Save prod config" I get: Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. Why this is happening?

    – G. G.
    Nov 21 '18 at 12:32













  • @G.G. in general the message "your branch is behind... and can be fast-forwarded" is not a warning, but just an indication that "git pull" wouldn't create a merge commit because master happens to be a direct ancestor of origin/master, so "git pull" would just update the local branch by moving the local branch to the latest upstream commit. However, it seems to me this situation should not have occurred given the use case you described in your question. Maybe check you have indeed run "git add ..." and that the commit has been successfully created in the good branch.

    – ErikMD
    Nov 21 '18 at 13:12













  • Instead of git merge, you could also use git fetch and a git merge --no-ff --no-commit if you want to review changes to production before you change something...

    – Christoph
    Nov 21 '18 at 15:11













  • @ErikMD understood. But the only change I have made in this server are the files I already mentioned. Please if I fast forward the master branch will I loose anything?

    – G. G.
    Nov 21 '18 at 19:34











  • @G.G. a fast-forward merge can't cause losing files. In general, with Git you can't lose changes, provided they have been committed at some point. E.g., you can always rollback HEAD to some previous state after inspecting its history with git reflog. But you said in a previous comment you had lost changes (maybe with a git checkout -- filenames command? which is indeed a destructive one) so hopefully you've already saved (committed) the files mentioned in your post.

    – ErikMD
    Nov 21 '18 at 20:17
















4














There are at least three different solutions to achieve this:





  • You can commit your changes on these two files in the production server, before running git pull:



    git add -v -u
    git commit -m "Save prod config"
    git pull


    This will typically create a merge commit combining the local branch (with the commit "Save prod config") and the changes from your remote.



    If there is some conflict, you'll just need to resolve it with the help of git status, git diff, and git commit.



    For subsequent updates, it should suffice to run git pull.




  • Like the previous solution, you can commit your changes on the two production config files, but run git pull -r afterwards:



    git add -v -u
    git commit -m "Save prod config"
    git pull -r


    The -r option stands for --rebase and means that the local commit(s) specific to the production server will be rebased on top of the pulled commits.



    Subsequent updates can be performed by running git pull -r.



    The main advantage of this solution is just the ability to keep a "linear history": there is no merge commit created and the "Save prod config" commit will always be replayed at the 'end' of the history.




  • or you can use the git stash command (which may have some drawbacks in case of conflict):



    git stash
    git pull
    git stash pop







share|improve this answer


























  • after git commit -m "Save prod config" I get: Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. Why this is happening?

    – G. G.
    Nov 21 '18 at 12:32













  • @G.G. in general the message "your branch is behind... and can be fast-forwarded" is not a warning, but just an indication that "git pull" wouldn't create a merge commit because master happens to be a direct ancestor of origin/master, so "git pull" would just update the local branch by moving the local branch to the latest upstream commit. However, it seems to me this situation should not have occurred given the use case you described in your question. Maybe check you have indeed run "git add ..." and that the commit has been successfully created in the good branch.

    – ErikMD
    Nov 21 '18 at 13:12













  • Instead of git merge, you could also use git fetch and a git merge --no-ff --no-commit if you want to review changes to production before you change something...

    – Christoph
    Nov 21 '18 at 15:11













  • @ErikMD understood. But the only change I have made in this server are the files I already mentioned. Please if I fast forward the master branch will I loose anything?

    – G. G.
    Nov 21 '18 at 19:34











  • @G.G. a fast-forward merge can't cause losing files. In general, with Git you can't lose changes, provided they have been committed at some point. E.g., you can always rollback HEAD to some previous state after inspecting its history with git reflog. But you said in a previous comment you had lost changes (maybe with a git checkout -- filenames command? which is indeed a destructive one) so hopefully you've already saved (committed) the files mentioned in your post.

    – ErikMD
    Nov 21 '18 at 20:17














4












4








4







There are at least three different solutions to achieve this:





  • You can commit your changes on these two files in the production server, before running git pull:



    git add -v -u
    git commit -m "Save prod config"
    git pull


    This will typically create a merge commit combining the local branch (with the commit "Save prod config") and the changes from your remote.



    If there is some conflict, you'll just need to resolve it with the help of git status, git diff, and git commit.



    For subsequent updates, it should suffice to run git pull.




  • Like the previous solution, you can commit your changes on the two production config files, but run git pull -r afterwards:



    git add -v -u
    git commit -m "Save prod config"
    git pull -r


    The -r option stands for --rebase and means that the local commit(s) specific to the production server will be rebased on top of the pulled commits.



    Subsequent updates can be performed by running git pull -r.



    The main advantage of this solution is just the ability to keep a "linear history": there is no merge commit created and the "Save prod config" commit will always be replayed at the 'end' of the history.




  • or you can use the git stash command (which may have some drawbacks in case of conflict):



    git stash
    git pull
    git stash pop







share|improve this answer















There are at least three different solutions to achieve this:





  • You can commit your changes on these two files in the production server, before running git pull:



    git add -v -u
    git commit -m "Save prod config"
    git pull


    This will typically create a merge commit combining the local branch (with the commit "Save prod config") and the changes from your remote.



    If there is some conflict, you'll just need to resolve it with the help of git status, git diff, and git commit.



    For subsequent updates, it should suffice to run git pull.




  • Like the previous solution, you can commit your changes on the two production config files, but run git pull -r afterwards:



    git add -v -u
    git commit -m "Save prod config"
    git pull -r


    The -r option stands for --rebase and means that the local commit(s) specific to the production server will be rebased on top of the pulled commits.



    Subsequent updates can be performed by running git pull -r.



    The main advantage of this solution is just the ability to keep a "linear history": there is no merge commit created and the "Save prod config" commit will always be replayed at the 'end' of the history.




  • or you can use the git stash command (which may have some drawbacks in case of conflict):



    git stash
    git pull
    git stash pop








share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 21 '18 at 12:27

























answered Nov 21 '18 at 12:04









ErikMDErikMD

2,4811521




2,4811521













  • after git commit -m "Save prod config" I get: Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. Why this is happening?

    – G. G.
    Nov 21 '18 at 12:32













  • @G.G. in general the message "your branch is behind... and can be fast-forwarded" is not a warning, but just an indication that "git pull" wouldn't create a merge commit because master happens to be a direct ancestor of origin/master, so "git pull" would just update the local branch by moving the local branch to the latest upstream commit. However, it seems to me this situation should not have occurred given the use case you described in your question. Maybe check you have indeed run "git add ..." and that the commit has been successfully created in the good branch.

    – ErikMD
    Nov 21 '18 at 13:12













  • Instead of git merge, you could also use git fetch and a git merge --no-ff --no-commit if you want to review changes to production before you change something...

    – Christoph
    Nov 21 '18 at 15:11













  • @ErikMD understood. But the only change I have made in this server are the files I already mentioned. Please if I fast forward the master branch will I loose anything?

    – G. G.
    Nov 21 '18 at 19:34











  • @G.G. a fast-forward merge can't cause losing files. In general, with Git you can't lose changes, provided they have been committed at some point. E.g., you can always rollback HEAD to some previous state after inspecting its history with git reflog. But you said in a previous comment you had lost changes (maybe with a git checkout -- filenames command? which is indeed a destructive one) so hopefully you've already saved (committed) the files mentioned in your post.

    – ErikMD
    Nov 21 '18 at 20:17



















  • after git commit -m "Save prod config" I get: Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. Why this is happening?

    – G. G.
    Nov 21 '18 at 12:32













  • @G.G. in general the message "your branch is behind... and can be fast-forwarded" is not a warning, but just an indication that "git pull" wouldn't create a merge commit because master happens to be a direct ancestor of origin/master, so "git pull" would just update the local branch by moving the local branch to the latest upstream commit. However, it seems to me this situation should not have occurred given the use case you described in your question. Maybe check you have indeed run "git add ..." and that the commit has been successfully created in the good branch.

    – ErikMD
    Nov 21 '18 at 13:12













  • Instead of git merge, you could also use git fetch and a git merge --no-ff --no-commit if you want to review changes to production before you change something...

    – Christoph
    Nov 21 '18 at 15:11













  • @ErikMD understood. But the only change I have made in this server are the files I already mentioned. Please if I fast forward the master branch will I loose anything?

    – G. G.
    Nov 21 '18 at 19:34











  • @G.G. a fast-forward merge can't cause losing files. In general, with Git you can't lose changes, provided they have been committed at some point. E.g., you can always rollback HEAD to some previous state after inspecting its history with git reflog. But you said in a previous comment you had lost changes (maybe with a git checkout -- filenames command? which is indeed a destructive one) so hopefully you've already saved (committed) the files mentioned in your post.

    – ErikMD
    Nov 21 '18 at 20:17

















after git commit -m "Save prod config" I get: Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. Why this is happening?

– G. G.
Nov 21 '18 at 12:32







after git commit -m "Save prod config" I get: Your branch is behind 'origin/master' by 3 commits, and can be fast-forwarded. Why this is happening?

– G. G.
Nov 21 '18 at 12:32















@G.G. in general the message "your branch is behind... and can be fast-forwarded" is not a warning, but just an indication that "git pull" wouldn't create a merge commit because master happens to be a direct ancestor of origin/master, so "git pull" would just update the local branch by moving the local branch to the latest upstream commit. However, it seems to me this situation should not have occurred given the use case you described in your question. Maybe check you have indeed run "git add ..." and that the commit has been successfully created in the good branch.

– ErikMD
Nov 21 '18 at 13:12







@G.G. in general the message "your branch is behind... and can be fast-forwarded" is not a warning, but just an indication that "git pull" wouldn't create a merge commit because master happens to be a direct ancestor of origin/master, so "git pull" would just update the local branch by moving the local branch to the latest upstream commit. However, it seems to me this situation should not have occurred given the use case you described in your question. Maybe check you have indeed run "git add ..." and that the commit has been successfully created in the good branch.

– ErikMD
Nov 21 '18 at 13:12















Instead of git merge, you could also use git fetch and a git merge --no-ff --no-commit if you want to review changes to production before you change something...

– Christoph
Nov 21 '18 at 15:11







Instead of git merge, you could also use git fetch and a git merge --no-ff --no-commit if you want to review changes to production before you change something...

– Christoph
Nov 21 '18 at 15:11















@ErikMD understood. But the only change I have made in this server are the files I already mentioned. Please if I fast forward the master branch will I loose anything?

– G. G.
Nov 21 '18 at 19:34





@ErikMD understood. But the only change I have made in this server are the files I already mentioned. Please if I fast forward the master branch will I loose anything?

– G. G.
Nov 21 '18 at 19:34













@G.G. a fast-forward merge can't cause losing files. In general, with Git you can't lose changes, provided they have been committed at some point. E.g., you can always rollback HEAD to some previous state after inspecting its history with git reflog. But you said in a previous comment you had lost changes (maybe with a git checkout -- filenames command? which is indeed a destructive one) so hopefully you've already saved (committed) the files mentioned in your post.

– ErikMD
Nov 21 '18 at 20:17





@G.G. a fast-forward merge can't cause losing files. In general, with Git you can't lose changes, provided they have been committed at some point. E.g., you can always rollback HEAD to some previous state after inspecting its history with git reflog. But you said in a previous comment you had lost changes (maybe with a git checkout -- filenames command? which is indeed a destructive one) so hopefully you've already saved (committed) the files mentioned in your post.

– ErikMD
Nov 21 '18 at 20:17




















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%2f53411493%2fgit-stash-uncommitted-files%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

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)