Submit

How to squash last X commits together

· Origin StackOverflow · Solving Mistories

In this example, we'll squash the last 3 commits. If you want to write the new commit message from scratch, this suffices:

$ git reset --soft HEAD~3 &&
$ git commit

If you want to start editing the new commit message with a concatenation of the existing commit messages, then you need to extract those messages and pass them to git commit:

$ git reset --soft HEAD~3 &&
$ git commit --edit -m"$(git log --format=%B --reverse [email protected]{1})"

Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash. Neither the index nor the working tree are touched by the soft reset, leaving the index in the desired state for your new commit (i.e. it already has all the changes from the commits that you are about to “throw away”).

How to checkout to a remote branch that someone else is working on in git?

· Flight Rules · Solving Mistories

First, fetch all branches from remote:

$ git fetch --all

Say you want to checkout to production from the remote.

$ git checkout --track origin/production
# Branch production set up to track remote branch production from origin.
# Switched to a new branch 'production'

(--track is shorthand for git checkout -b [branch] [remotename]/[branch])

This will give you a local copy of the branch production, and any update that has been pushed will also show up remotely

Fuck this noise, I give up.

· OhShitGit · Fuck
$ cd ..
$ sudo rm -r fucking-git-repo-dir
$ git clone https://some.github.url/fucking-git-repo-dir.git
$ cd fucking-git-repo-dir

Want to Contribute?

Send me an Email, ping me on Twitter or submit a pull request on Github.

Sign up below to receive updates, tips and more handy tutorials when git screws up. It’s good stuff & I don’t spam.