Questions tagged [git-rebase]

With the git-rebase command, you can take the changes from one branch and replay them on top of another branch.

git rebase allows you to specify the starting point of a branch, that is, to "move" changes from a branch on top of another branch. You can also specify specific commits even if they don't have branches associated with them

The Git book has a chapter on rebasing has some nice examples with diagrams that help to understand the general concept, although each system has different capabilities.

Another common way to integrate changes is to merge to branches. The difference between these two operation has been covered in Stack Overflow:

Also on the usage of git svn the equivalent to git pull is a git svn rebase that rebases local changes ahead of the commits existing in the subversion repository.

A rebase can be undone as explained in "Undoing a rebase"

1451 questions
3568
votes
33 answers

Delete commits from a branch in Git

I would like to know how to delete a commit. By delete, I mean it is as if I didn't make that commit, and when I do a push in the future, my changes will not push to the remote branch. I read git help, and I think the command I should use is git…
hap497
  • 129,793
  • 42
  • 77
  • 91
3500
votes
18 answers

Undoing a git rebase

Does anybody know how to easily undo a git rebase? The only way that comes to mind is to go at it manually: git checkout the commit parent to both of the branches then create a temp branch from there cherry-pick all commits by hand replace the…
webmat
  • 50,648
  • 12
  • 52
  • 59
1698
votes
17 answers

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?
Coocoo4Cocoa
  • 41,896
  • 50
  • 148
  • 175
1108
votes
7 answers

How to rebase local branch onto remote master

I have a cloned project from a master branch from remote repository remote_repo. I create a new branch and I commit to that branch. Other programmers pushed to remote_repo to the master branch. I need now to rebase my local branch RB onto…
Damir
  • 48,513
  • 89
  • 234
  • 352
1060
votes
12 answers

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: checkout first branch cherry-pick one by one c to f and…
tig
  • 21,082
  • 10
  • 60
  • 93
1007
votes
11 answers

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 heard that Git is excellent for branching and merging,…
Micah
  • 16,906
  • 7
  • 38
  • 46
817
votes
20 answers

How to remove/delete a large file from commit history in Git repository?

I accidentally dropped a DVD-rip into a website project, then carelessly git commit -a -m ..., and, zap, the repo was bloated by 2.2 gigs. Next time I made some edits, deleted the video file, and committed everything, but the compressed file is…
culebrón
  • 28,179
  • 18
  • 66
  • 97
600
votes
9 answers

Squash the first two commits in Git?

With git rebase --interactive you can squash any number of commits together into a single one. That's all great unless you want to squash commits into the initial commit. That seems impossible to do. Are there any ways to achieve…
kch
  • 71,135
  • 44
  • 128
  • 148
550
votes
19 answers

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 one?
Verhogen
  • 23,861
  • 32
  • 81
  • 109
539
votes
8 answers

What's the difference between 'git merge' and 'git rebase'?

What's the difference between git merge and git rebase?
Daniel Peñalba
  • 27,557
  • 31
  • 124
  • 209
435
votes
4 answers

What is the difference between merge --squash and rebase?

I'm new to git and I'm trying to understand the difference between a squash and a rebase. As I understand it you perform a squash when doing a rebase.
GiH
  • 11,696
  • 13
  • 40
  • 53
428
votes
9 answers

Your branch is ahead of 'origin/master' by 3 commits

I am getting the following when running git status Your branch is ahead of 'origin/master' by 3 commits. I have read on some other post the way to fix this is run git pull --rebase but what exactly is rebase, will I lose data or is this simple way…
FluxEngine
  • 10,860
  • 13
  • 49
  • 78
380
votes
8 answers

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 Added that folder to git repository and pushed the…
Kartik
  • 8,035
  • 8
  • 45
  • 52
374
votes
34 answers

git rebase: "error: cannot stat 'file': Permission denied"

I'm using git, and made a small commit followed by a large one. I decided to use git rebase to squash the two commits together before pushing them. (I've never done this before.) So I did: git rebase -i HEAD~2 This gave me my editor, where I chose…
Ryan Lundy
  • 187,365
  • 35
  • 174
  • 206
373
votes
2 answers

How to get "their" changes in the middle of conflicting Git rebase?

I have conflicting branches, branch2 branched from branch1. Let's say when rebasing branch2 on current branch1, while resolving conflicts, I decide to take some (not all) of "their" (i.e. branch1) files as-is. How do I do that? I tried: git checkout…
Ondra Žižka
  • 36,997
  • 35
  • 184
  • 250
1
2 3
96 97