In most cases, when you do some work, each completes the changes that need to be saved in different commits.
I am looking for the best methods to do this in a good way.
Of course, the main answer is to use git add -p.
The problem with this basic answer is that it does not allow checking the state of the storage before committing it. Very often, this would mean forgetting to add some import, or forgetting the dependency between some phased code and some uninstalled parts. As a result, this commit will not transfer the assembly.
So I'm looking for a way to create multiple commits, with the ability to run tests for each commit.
The workflows I've tried so far are as follows:
Workflow 1: commit, print, then check
As long as there is more than 1 commit for current changes, repeat:
git add -N <new files> # To mark all new files as potentially stageablegit add -p # To add only first commit changesgit commitgit stash save -k -u- run tests
- until the tests pass
git stash pop- fix code
- git add appropriate changes
git commit --amend --no-editgit stash save -k -u
git stash pop
The main problem that I am encountering with this workflow is the fact that it does not make much sense to accomplish something without testing it, knowing that it will be fixed soon.
Workflow 2: stash, test and commit
As long as there is more than 1 commit for current changes, repeat:
git add -N <new files> # To mark all new files as potentially stageablegit add -p # To add only first commit changesgit stash save -k -u # To remove everything that was not added- run tests
- until the tests pass
git stash pop- fix code
- git add appropriate changes
git stash save -k -u
git commitgit stash pop
The main problem that I find in this workflow is that it git stash popoften fails with conflict . This makes it necessary to repeat git add -pconflicts in all files, which can take a lot of time. This happens, among other things, when you try to add only part of a new file.
?