# s, squash = use commit, but meld into previous commit # e, edit = use commit, but stop for amending # r, reword = use commit, but edit the commit message This command will open a temporary file in your editor that will look something like this: pick 7f35639 did some lot If you're unsure of how many commits you've made or want to squash, you can always use $ git log to get a history of all of the commits in your current branch.įor example, if I want to squash my project's last three commits into a single commit before pushing it to my master branch, I would run the following: The -i flag runs the command in interactive mode, which allows us to modify individual commits instead of blindly squashing them. Where X is the number of commits to squash. To squash your commits, you'll want to use the following command: Use this command wisely to avoid accidentally losing commits. Note: Keep in mind that when you use the rebase command you are literally rewriting your branch's history. Without this flag, Sublime will immediately return after it opens a temporary file, which would result in the rebase command finishing before you've had a chance to change anything. More importantly, you'll see I've added the -w flag to this argument, which is a command line argument that tells Sublime to wait for the files to be closed before returning. $ git config -global core.editor "subl -w" I use Sublime Text, so I've set my core.editor configuration to subl, as seen here: Git Configurationįirst, be sure that Git is configured to use the editor you typically work in. This post is going to walk you through a simple Git repository rebase. If these PRs did not squash their commits, the repo's changelog would be incredibly difficult to keep track of due to the insane amount of commits it would be tracking. There's many times when collaborating on Git that you may need to combine, or "squash" multiple commits into a single commit.įor example, the repository I'm currently working on at my internship with BuzzFeed has 8,500+ commits and hundreds of open pull requests at any given time.
0 Comments
Leave a Reply. |