Skip to content

Instantly share code, notes, and snippets.

@jendiamond
Last active February 23, 2021 23:12
Show Gist options
  • Save jendiamond/6325286 to your computer and use it in GitHub Desktop.
Save jendiamond/6325286 to your computer and use it in GitHub Desktop.
Week 6 Day 29

$ git checkout master 

$ git pull upstream master 

$ git checkout faqpage 

$ git rebase -i master

Successfully rebased and updated refs/heads/master.

** Change the word "pick" to "s**

Then run

$ git push -f origin faqpage

$ git fetch upstream
$ git checkout omgpull 
$ git rebase -i upstream/master

< choose squash for all of your commits, except the first one >
< Edit the commit message to make sense, and describe all your changes >

$ git push origin omgpull -f

When you run this command this will pop up...

noop

# Rebase cbaf836..cbaf836 onto cbaf836
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

Rebasing from upstream master

git checkout faqpage
git pull --rebase upstream master
git push -f origin faqpage

The following directions are from http://git-scm.com/

It’s important to note that these commits are listed in the opposite order than you normally see them using the log command. If you run a log, you see something like this:

$ git log --pretty=format:"%h %s" HEAD3..HEAD a5f4a0d added cat-file 310154e updated README formatting and added blame f7f3f6d changed my name a bit Notice the reverse order. The interactive rebase gives you a script that it’s going to run. It will start at the commit you specify on the command line (HEAD3) and replay the changes introduced in each of these commits from top to bottom. It lists the oldest at the top, rather than the newest, because that’s the first one it will replay.

You need to edit the script so that it stops at the commit you want to edit. To do so, change the word pick to the word edit for each of the commits you want the script to stop after. For example, to modify only the third commit message, you change the file to look like this:

edit f7f3f6d changed my name a bit pick 310154e updated README formatting and added blame pick a5f4a0d added cat-file When you save and exit the editor, Git rewinds you back to the last commit in that list and drops you on the command line with the following message:

$ git rebase -i HEAD~3 Stopped at 7482e0d... updated the gemspec to hopefully work better You can amend the commit now, with

   git commit --amend

Once you’re satisfied with your changes, run

   git rebase --continue

These instructions tell you exactly what to do. Type

$ git commit --amend Change the commit message, and exit the editor. Then, run

$ git rebase --continue This command will apply the other two commits automatically, and then you’re done. If you change pick to edit on more lines, you can repeat these steps for each commit you change to edit. Each time, Git will stop, let you amend the commit, and continue when you’re finished.

@jendiamond
Copy link
Author

jendiamond commented Feb 23, 2021

I have done a search for this post many times. Thank you past self. 🥇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment