313 questions
1170 votes
24 answers
537k views
How can I remove/delete a large file from the commit history in the Git repository?
I accidentally dropped a DVD-rip into a website project, carelessly git commit -a -m ..., and, zap, the repository was bloated by 2.2 GB. Next time I made some edits, deleted the video file, and ...
4499 votes
42 answers
5.7m views
How do I delete a commit from a branch?
How do I delete a commit from my branch history? Should I use git reset --hard HEAD?
2539 votes
19 answers
1.2m views
When do you use Git rebase instead of Git merge?
When is it recommended to use Git rebase vs. Git merge? Do I still need to merge after a successful rebase?
4460 votes
22 answers
2.4m views
Undoing a git rebase
How do I easily undo a git rebase? A lengthy manual method is: checkout the commit parent to both of the branches create and checkout a temporary branch cherry-pick all commits by hand reset the ...
422 votes
3 answers
162k views
What exactly does git's "rebase --preserve-merges" do (and why?)
Git's documentation for the rebase command is quite brief: --preserve-merges Instead of ignoring merges, try to recreate them. This uses the --interactive machinery internally, but combining it ...
1046 votes
11 answers
236k views
Git workflow and rebase vs merge questions
I've been using Git now for a couple of months on a project with one other developer. I have several years of experience with SVN, so I guess I bring a lot of baggage to the relationship. I have ...
1660 votes
17 answers
1.3m views
How to cherry-pick multiple commits
I have two branches. Commit a is the head of one, while the other has b, c, d, e and f on top of a. I want to move c, d, e and f to first branch without commit b. Using cherry pick it is easy: ...
831 votes
25 answers
603k views
How to squash all git commits into one?
How do you squash your entire repository down to the first commit? I can rebase to the first commit, but that would leave me with 2 commits. Is there a way to reference the commit before the first ...
639 votes
6 answers
378k views
What is the difference between merge --squash and rebase?
I am trying to understand the differences between git merge --squash <branch> and git rebase [--interactive] <base>. Depending on the command, I am not sure what new commits appear on the ...
416 votes
5 answers
66k views
Edit the root commit in Git?
There's ways to change the message from later commits: git commit --amend # for the most recent commit git rebase --interactive master~2 # but requires *parent* How can you ...
691 votes
8 answers
344k views
What's the difference between 'git merge' and 'git rebase'?
What's the difference between git merge and git rebase?
295 votes
16 answers
78k views
Insert a commit before the root commit in Git?
I've asked before about how to squash the first two commits in a git repository. While the solutions are rather interesting and not really as mind-warping as some other things in git, they're still a ...
238 votes
9 answers
53k views
Combine the first two commits of a Git repository?
Suppose you have a history containing the three commits A, B and C: A-B-C I would like to combine the two commits A and B to one commit AB: AB-C I tried git rebase -i A which opens up my editor ...
93 votes
3 answers
19k views
How do I recover/resynchronise after someone pushes a rebase or a reset to a published branch?
We have all heard that one should never rebase published work, that it’s dangerous, etc. However, I have not seen any recipes posted for how to deal with the situation in case a rebase is published. ...
530 votes
11 answers
219k views
Remove folder and its contents from Git/GitHub's history
I was working on a repository on my GitHub account and this is a problem I stumbled upon. Node.js project with a folder with a few npm packages installed The packages were in node_modules folder ...