git-plus
git-plus copied to clipboard
Interactive rebase
I tried Run and then "git rebase -i master" but it didn't work. Is there a way to do that?
To make this work, you'll need to have atom set as your editor of choice in the git config. You can do that with this command git config [--global] core.editor "atom --wait"
. Making it global is up to you.
Then you can use run to enter the rebase command. Because of the "--wait" flag, it will open a new window for doing the rebase and wait until that window is closed to finish the process.
Hi @akonwi, how feasible would it be to have a GitRebaseInteractive command that would work similar to the GitCommit command ?
Is it more difficult because of the potential two steps in the interactive rebase (one for pick, squash, etc, the other to edit the commit messages) ?
In any case, I'm currently using the solution presented here https://aj-foster.com/2016/git-commit-atom/.
I modified the script to work for git-rebase-todo as well as for COMMIT_EDITMSG
@jbrodriguez Yea this wouldn't be trivial because right now the other commands from this package just fire off commands in child processes and and an interactive rebase requires a lot of back and forth between the editor and git's CLI.
If that solution you've linked to is working that is pretty cool! That could potentially be incorporated into the package
@jbrodriguez would you mind sharing the code that makes it work with git-rebase-todo?
@roblafeve sure ...
Using https://aj-foster.com/2016/git-commit-atom/ as a base, I modified the script in the article to read
git-commit-atom
#!/usr/bin/env bash
# Get the location of the file to edit from Git.
FILE_TO_EDIT="$1"
# If the file we're editing is a commit message, we can assume Atom is set up
# to insert the magic token when the editor closes. Otherwise, we need to let
# Atom tell Git when it is done.
#
if [[ $(basename "$FILE_TO_EDIT") == "COMMIT_EDITMSG" || $(basename "$FILE_TO_EDIT") == "git-rebase-todo" ]]
then
# Tell Atom to open the file in an existing window.
atom "$FILE_TO_EDIT"
# Wait for Atom to write the magic marker - ##ATOM EDIT COMPLETE## - to signal
# that the editor has been closed.
#
tail -f "$FILE_TO_EDIT" | while read LOGLINE
do
[[ "$LOGLINE" == "##ATOM EDIT COMPLETE##" ]] && pkill -P $$ tail
done
else
# Tell Atom to open the file in a new window and report when it is finished.
atom --wait "$FILE_TO_EDIT"
fi
and the Atom Init Script is now
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
# console.log "Saved! #{editor.getPath()}"
# This writes a magic token to the end of a commit message. We expect this to
# be run when the commit message editor has been closed.
#
commit_msg_notifier = (path) ->
process = require("child_process")
process.exec("echo \"##ATOM EDIT COMPLETE##\" >> " + path)
# The following looks at all new editors. If the editor is for a COMMIT_EDITMSG
# file, it sets up a callback for a magic token to be written when the editor
# is closed.
#
setup_commit_msg_notifier = (editor) ->
name = editor.buffer?.file?.getBaseName()
if name == "COMMIT_EDITMSG" || name == "git-rebase-todo"
path = editor.buffer.file.getPath()
editor.onDidDestroy ->
commit_msg_notifier(path)
# Return this, else weird things may happen. Anyone understand why?
true
# Set up for all editors to be screened for commit messages.
atom.workspace.observeTextEditors(setup_commit_msg_notifier)
finally I invoke git rebase like this
GIT_EDITOR="/path/to/git-commit-atom" git rebase -i origin/master
This is because I prefer not to alter the git editor globally, so I make it work locally just for the git rebase command.
I have a couple of shell functions that hide the syntax for me.
I'm using a git flow that is a slight variation of the hybrid approach shown here: https://gist.github.com/jbrodriguez/480fd9e474579d041860fc7ffb0eaaf2
@jbrodriguez thanks for this! I'll give it a try 👍