gitless
gitless copied to clipboard
error when switching branches
Lately I found myself kind of trapped in a corner.
My master branch is for production ready code. So when I have to change the code I'm supposed to create a branch and switch to it before making any changes. The thing is that I forget to do that. So I end up with modified files while on the master branch and I need to move the changes to the new branch. But switching to the new branch stashes the changes in master.
Is there an easy way to "move" these modified files into the new branch ?
What I had to do is manually copy the modified files outside of the repo directory. Checkout the original files. Switch to the new branch and copy back the modified files.
This happened to me a few times and there is no way to protect myself against it. So is there a trick to get out of such corner I get trapped in ? I know I could also use git stash to get around this problem. But I'm trying to be a pure gitless user.
I really like the automatic stash when switching, but the possibility to "move" modified files from one branch to the other as cherry picking commits could be useful.
You can use the -mo/--move-over flag of gl switch
Excellent. Thank you very much.
I just tried it and got an error.
10:00 $ gl switch -mo master
Traceback (most recent call last):
File "gl.py", line 14, in <module>
File "gitless/cli/gl.py", line 87, in main
File "gitless/cli/pprint.py", line 80, in err
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 71: ordinal not in range(128)
Failed to execute script gl
However, the move succeeded. I ended on the branch master with my modified file. And the modified file was removed from the branch left.
I also noticed that the number of stashes are growing. I suspect the error is in the code that removes the stash.
After removing all the stashes, the error disappeared. However I met another problem.
$ gl switch feature-change-log-into-glog
✔ Switched to branch feature-change-log-into-glog
- ~/Sources/go/src/FileSync [feature-change-log-into-glog *|-]
10:46 $ vim build.sh
- ~/Sources/go/src/FileSync [feature-change-log-into-glog *|!1]
10:46 $ gl switch -mo master
✔ Switched to branch master
- ~/Sources/go/src/FileSync [master|!1]
10:47 $ gl switch feature-change-log-into-glog
✔ Switched to branch feature-change-log-into-glog
- ~/Sources/go/src/FileSync [feature-change-log-into-glog *|>1]
10:47 $ gl switch -mo master
✘ fatal: Unable to mark file .gitignore build.sh fileSyncServer/main.go fileSyncServer/server.go fileSyncServer/session.go test/runMe.sh
Explanation: The test is performed after erasing all stashes while I'm in the master branch.
- I switch to the feature branch. The prompt (from bash-git-prompt) displays the status. The * means that the branch has no remote, and the - means that there are no modified files or untracked files.
- I modify the build.sh file. The - is replaced by !1 which means that there is one modified file.
- I switch to the master branch with the -mo. This worked without error this time. I now have a modified file in master.
- I switch back to the feature branch to check if the modified file is still there, but it's been moved to master. Perfect.
- switch back to master using -mo (sorry for being nasty) and get the weird error shown above. However the command still completes, and I end up on the branch master without a clue of what happened. I would expect/prefer that if a command fails for whatever reason, that the state remains unchanged.
After further testing, I get the same error message even without the -mo option. The '>1' means that there is one stash. At least this number doesn't grow any more.