![]() Your changes will be put back and you can continue what you were doing initially. ![]() Reset back to the original commit but checkout theonefile from the new commit: git reset -hard HEAD git checkout A path/to/theonefile. You can now switch back to master $ git checkout masterĭo whatever changes you want on master, and when ready, go back to new-branch. One complicated way would be to first commit everything: git add -u git commit // creates commit with sha-1 A. Instead of committing your changes or reverting, you can stash them with: $ git stash save "changes on new-branch" One solution: git stash Stash the changes Git does not allow you to switch back to master because you have changes on new-branch. Please, commit your changes or stash them before you can switch branches. If you want to switch back to master, you will get an error message: $ git checkout masterĮrror: Your local changes to the following files would be overwritten by checkout: On top of that you have some pending changes on new-branch echo change > file1.txt # change file1Įcho change2 > file1.txt # change file1 again ![]() Git checkout -b new-branch # create a new branch and switch to that branch Git commit -m "Initial commit" # commit both files If you want to follow along here is the script mkdir testgitstash # create directoryĬd testgitstash # change to that directory We have 2 files: file1.txt and file2.txt and 2 branches, master and new-branch. Well there is a better solution: git stash. You can either commit if you are ready for it, or maybe you have only modified a few lines and can simply revert your changes. Before that happens, you have to take care of all your current changes. You need to switch back to your main dev branch. Common everyday scenario: you are working on your feature branch fixing a bug and your boss asks you for a build.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |