Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issues with Git - rebase / squash

I'm trying to squash a few commits in a git repository.

> git rebase -i HEAD~3

Successfully rebased and updated refs/heads/staging.

A file opens titled git-rebase-todo :

pick a2f3467 Require statement incorrect pick c41212e Require file in environment pick 2743221 This should work  # Rebase c5f42f3..2743221 onto c5f42f3 # .......... 

I tried changing the bottom two commits to squash from pick . I save the file, and I get the following error:

Unable to save ~/Documents/code/myapp/.git/rebase-emrge/git-rebase-todo

like image 293
Brandon Avatar asked Mar 13 '13 11:03

Brandon


People also ask

What is the main issue with git rebase?

The golden rule of git rebase is to never use it on public branches. The rebase moves all of the commits in main onto the tip of feature . The problem is that this only happened in your repository. All of the other developers are still working with the original main .

Why you should never rebase in git?

Rebasing can be dangerous! Rewriting history of shared branches is prone to team work breakage. This can be mitigated by doing the rebase/squash on a copy of the feature branch, but rebase carries the implication that competence and carefulness must be employed.

Should I squash or rebase?

squash does not touch your source branch ( tmp here) and creates a single commit where you want. rebase allows you to go on on the same source branch (still tmp ) with: a new base. a cleaner history.

Does git rebase cause conflicts?

When you perform a git rebase operation, you're typically moving commits around. Because of this, you might get into a situation where a merge conflict is introduced. That means that two of your commits modified the same line in the same file, and Git doesn't know which change to apply.


1 Answers

The problem is that when sublimetext2 is started, it doesn't block and immediately returns. Git then thinks that you're done editing the file and performs the rebase. That's why you see the

Successfully rebased and updated refs/heads/staging 

message, before you even edited the file. Use the subl command instead, which is designed for such use. The github help tells you do configure it with

git config --global core.editor "subl -n -w" 
like image 164
Michael Wild Avatar answered Oct 14 '22 23:10

Michael Wild