Git rebase - re-create result of a command (yarn.lock file, etc)

Viewed 28

Getting this error:

Executing: git reset --soft HEAD~ && git restore --staged yarn.lock && git restore yarn.lock && yarn install && git add yarn.lock && git rebase --continue
yarn install v1.22.19
[1/5]   Validating package.json...
[2/5]   Resolving packages...
[3/5]   Fetching packages...
[4/5]   Linking dependencies...
[5/5]   Building fresh packages...
success Saved lockfile.
✨  Done in 10.29s.
error: could not open '/Users/devinrhode2/repos/myco/tess1/.git/worktrees/tess3/rebase-merge/author-script' for reading: No such file or directory
error: you have staged changes in your working tree
If these changes are meant to be squashed into the previous commit, run:

  git commit --amend 

If they are meant to go into a new commit, run:

  git commit 

In both cases, once you're done, continue with:

  git rebase --continue

error: could not commit staged changes.
error: cannot rebase: Your index contains uncommitted changes.
warning: execution failed: git reset --soft HEAD~ && git restore --staged yarn.lock && git restore yarn.lock && yarn install && git add yarn.lock && git rebase --continue
and made changes to the index and/or the working tree
You can fix the problem, and then run

  git rebase --continue


hint: Could not execute the todo command
hint: 
hint:     exec git reset --soft HEAD~ && git restore --staged yarn.lock && git restore yarn.lock && yarn install && git add yarn.lock && git rebase --continue
hint: 
hint: It has been rescheduled; To edit the command before continuing, please
hint: edit the todo list first:
hint: 
hint:     git rebase --edit-todo
hint:     git rebase --continue

The spirit of what I'm trying to do, is essentially re-generate the changes to yarn.lock file from the previous commit (but on the new base). It's easier to simply re-generate the changes than to validate them.

2 Answers

It seems you simply still need to commit the changed yarn.lock file. You do a git add command, which stages the file, but does not actually commit the result. Therefore at the point where you are trying to continue the rebase, your git working tree is still dirty, so git refuses to continue the rebase. As git already indicates itself, you should add a git commit or git commit --amend command

@Johan

It's looking like this rebase recipe may look something like:

pick 6a33e8ebe Run `yarn add eslint --dev`
exec LAST_MSG=$(git log -1 --format=%B 6a33e8ebe); git reset --soft HEAD~ && git restore --staged yarn.lock && git restore yarn.lock && yarn install && git add yarn.lock && git commit -m "$LAST_MSG"

Of course, there's the complication of actually getting that hash in there for the LAST_MSG - should be able to reference just HEAD tho, I think.

UPDATE: Actually, ideal pattern is for commands to have their own single commit, and do:

drop bde6f678a Run `yarn prettier --write README.md .eslintrc.js`
exec yarn prettier --write README.md .eslintrc.js && git commit -am "Run `yarn prettier --write README.md .eslintrc.js`"

Git should probably introduce a commit message syntax like:

git commit -am "exec! yarn prettier --write README.md .eslintrc.js"

When rebasing, it would basically expand to this:

drop bde6f678a Run `yarn prettier --write README.md .eslintrc.js`
exec yarn prettier --write README.md .eslintrc.js && git commit -am "exec! yarn prettier --write README.md .eslintrc.js"

Commits can never be small enough!

Related