I recommend you use git stash to temporarily save it, and when you switch back, use git stash apply to reacquire the changes just now. Give you a clean working directory when switching:)
There are several processing methods as follows:
1. Add and commit, then checkout, and commit to the current branch
2. Add but not commit, you can stash, then checkout and stash apply, then commit, commit to the current branch
3. Add but do not commit or stash, directly checkout, and then commit, the record will be under the switch branch.
The reason behind it: A local git repo has only one workspace and staging area, but has multiple branch submission areas, and our checkout just switches the HEAD pointer from one branch to another.
If your current branch has been modified but has not been committed yet, if you want to switch branches, is it best to commit all the contents?
No, because your change is not necessarily ready for commit. Depending on your actual situation, you can use git stash to temporarily store it, you can commit to generate a new submission, or you can use git checkout -f to force branch switching
There is no commit and branch switching, the current file is still in the buffer.
It is not committed to the current Git version.
You can also reset, modify or commit under any branch.
Test
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git br a
git br
git br b
git co a
touch a.py
git add .
git co b
git st
git add .
git commit -m 'add a.py file'
git st
当前文件就回出现b分支下
如果这样,退回上次commit
git reset --hard
If there is no one with the same name, you can switch whether it is in the staging area or not tracked. After the switch, everything is business as usual. But if there is one with the same name, git will remind you that it is easily overwritten and will not allow you to operate.
I recommend you use git stash to temporarily save it, and when you switch back, use git stash apply to reacquire the changes just now. Give you a clean working directory when switching:)
There are several processing methods as follows:
1. Add and commit, then checkout, and commit to the current branch
2. Add but not commit, you can stash, then checkout and stash apply, then commit, commit to the current branch
3. Add but do not commit or stash, directly checkout, and then commit, the record will be under the switch branch.
The reason behind it: A local git repo has only one workspace and staging area, but has multiple branch submission areas, and our checkout just switches the HEAD pointer from one branch to another.
No, because your change is not necessarily ready for commit. Depending on your actual situation, you can use git stash to temporarily store it, you can commit to generate a new submission, or you can use git checkout -f to force branch switching
There is no commit and branch switching, the current file is still in the buffer.
It is not committed to the current Git version.
You can also reset, modify or commit under any branch.
Test
If there is no one with the same name, you can switch whether it is in the staging area or not tracked. After the switch, everything is business as usual.
But if there is one with the same name, git will remind you that it is easily overwritten and will not allow you to operate.