Git interactive reboot, edit specific commit without having to use an editor?

Currently I need to do: git rebase -i f47adfa0which show me:

pick 447a1cb Either left or right
pick ef35186 Introducing side effects

Then I change it to:

edit 447a1cb Either left or right
pick ef35186 Introducing side effects

If I would like to editspecify a specific commit ( 447a1cbin this case), is there a command that I can use to directly invoke this state? Instead of going through the above procedure?

+4
source share
3 answers

I can't think of a quick way to do this. Here is one way. It works no matter how far backward the commit occurs, but note that it rebasewill use any merges along the way. *

git checkout 447a1cb
<edit stuff>
git commit --amend
git checkout -
git rebase --onto @{-1} 447a1cb

, 447a1cb ; , , , HEAD^, .

:

  • , ( : " HEAD", , , , , 5).
  • ,
  • , , .. ,
  • (4), HEAD^ ( , .. ) . --onto , .

man git -rebase.

, .


* , , , --preserve-merges git rebase ( BUGS man git -rebase), git replace --edit git filter-branch. man git -replace man git -filter .

+3

IIUC, , rebase:

 $ git checkout -b temp-branch <SHA1>
 $ git commit --amend -m 'new commit message'
 $ git checkout -
 $ git rebase @{-1}
 $ git branch -d @{-1}
+1

sed git rebase:

EDITOR='sed -i 1s/pick 447a1cb/edit 447a1cb/' git rebase -i f47adfa0

Make a reuse command:

git config alias.edit-commit \
  '!f(){ EDITOR="sed -i 1s/pick/edit/" git rebase -i "$1"^; }; f'

Then:

git edit-commit 447a1cb
# make changes
git commit --amend
git rebase --continue
0
source

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


All Articles