1,774 questions
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?
6 votes
1 answer
809 views
Rebase "fixup" commit into prior merge commit
I have performed the following merge: A---B---C---E (HEAD, merge of C and D) / D---| But I noticed some issues in E, and fixed them in F: A---B---C---E---F (HEAD) / ...
3 votes
1 answer
126 views
How to keep git notes through a rewrite (rebase/rename/amend)?
I have added some notes to commits using git notes add <hash> -m potato But when I rebase or amend the commits, the note is not copied over to the new rewritten commit. According to the docs ...
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 ...
1 vote
4 answers
82 views
git rebase conflict take all changes from head on single file
If I have merge conflicts, how can I take all changes from HEAD for a single file? Not for the whole rebase, but for a single file? Is this possible, or do I have to manually change it?
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 ...
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 ...
0 votes
1 answer
96 views
Is there a way to run a command if a rebase step fails with a merge conflict?
While doing lots of branch-management via rebasing I have a number of common situations that cause merge conflicts to occur for which I have developed helper scripts that resolve the situation. When ...
272 votes
9 answers
86k views
git rebase without changing commit timestamps
Would it make sense to perform git rebase while preserving the commit timestamps? I believe a consequence would be that the new branch will not necessarily have commit dates chronologically. Is that ...
4 votes
3 answers
98 views
Looking for a clean way to reword a few commits from before multiple merges were done without having to re-resolve conflicts
Note: I have already looked at the following answers and they don't seem to apply or work in the way I expect them to work: Reword one commit prior to merge Squashing old git commits that were before ...
182 votes
6 answers
354k views
git remove merge commit from history
My Git history looks like that : I would like to squash the purple commits into a single one. I don't want to see them ever again in my commit log. I've tried to do a git rebase -i 1, but even though ...
2 votes
1 answer
100 views
Why does "git rebase" continue to conflict after choosing the "--ours" version of a file the first time?
I pulled from origin main, and I'm having issues handling conflicts on my branch. I did the following git checkout test (name of my branch) git pull origin main It tells me I have conflicts and is ...
0 votes
2 answers
83 views
How to rebase/? a fork of a FOSS project so when I submit a PR my multiple commits/syncs show as 1 commit? [closed]
UPDATE: The 1st question below has been resolved. My remaining question is what is the best way to rebase a fork before I submit a PR to a FOSS project so my changes (of multiple commits and sync's) ...
-2 votes
1 answer
135 views
I only edit one commit in an interactive rebase and pick the rest. What makes the result squashing them into one?
My history is linear: ... — B — C I make an interactive rebase to B~1 and set to edit B, pick C. All I do with B is to add a file to the gitignore, rm --cache -r . and commit --amend --no-edit it. ...
356 votes
10 answers
276k views
How to git rebase a branch with the onto command?
I have noticed that the two blocks of following git commands have different behaviours and I don't understand why. I have an A and a B branches that diverge with one commit ---COMMIT--- (A) \ --- (B) ...