![]() ![]() Your changes will be put back and you can continue what you were doing initially. 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. 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 This is a convenient shortcut for: git branch git switch . Create a new branch named starting at before switching to the branch.Git does not allow you to switch back to master because you have changes on new-branch. You can leave out at most one of A and B, in which case it defaults to HEAD. 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. If it aborts, git stash your changes and retry, or you can use the -hard option to lose the changes even from files that didnt change between the commits. 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. In such a situation, you can git branch new-branch to get your commits in a new branch followed by git reset -hard origin/main to reset the main branch to. 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. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |