Git - Commit and push local changes without losing file diffs?

I'm in VSCode and just made a ton of changes on my branch. I have a rough draft that would be a shame to lose due to to not backing up online. So naturally it would be smart to git add . my changes, then git push origin myBranch to create a remote backup.

But doing so will remove all my file diffs that Visual Studio Code's interface shows me in the sidebar (see picture below). Is there a way I can push to a remote branch but still keep the changes unstaged (or bring them back to unstaged), or any way to at least keep those diff files so I can still continue work on my local and easily be able to see everywhere that I touched?

7 files changed, clicking here will show all my diffs

3 answers

  • answered 2022-05-07 03:51 razer

    what will you push if you don't have any changes?

    simple solution will be . keep a copy all the files that you have made changes, then undo changes.

    later you can refer to the changes from copied files

  • answered 2022-05-07 03:55 memo

    save your work by using git stash. after pushing committed changes then you can call uncommitted changes as git stash pop. see the documentation here

  • answered 2022-05-07 07:52 j6t

    You make a commit and push it to make the remote backup.

    Then you discard the commit locally with

    git reset HEAD~
    

    This points your branch to the previous commit and leaves all changes in the files so that you can see the diffs.

    Be aware that you will have to force-push your branch later on when you have finished your local commits. That may or may not be a problem depending on how your remote repository is set up.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum