Save work in a few commits

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 stageable
  • git add -p # To add only first commit changes
  • git commit
  • git stash save -k -u
  • run tests
  • until the tests pass
    • git stash pop
    • fix code
    • git add appropriate changes
    • git commit --amend --no-edit
    • git 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 stageable
  • git add -p # To add only first commit changes
  • git 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 commit
  • git 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.

?

+4
2

stash, rebase. .

git gui , .

Implement feature A
Refactor mess B
f A 1
f A 2
f B 3
Improve formatting
f A 4
f B 5

"f A" "fixup for A".

git rebase -i

, ,

git rebase -i HEAD~8

Improve formatting
Implement feature A
f A 1
f A 2
f A 4
Refactor mess B
f B 3
f B 5

, , . git diff ORIG_HEAD, , .

"pick" "f" (fixup), .

rebase. "pick" "e" (), git ( git rebase --continue ).

, , , , , .

, , .

+1

- CI ( ). , , CI , checkout .

0

Source: https://habr.com/ru/post/1693117/


All Articles