Git interactive rebase no commits to pick

GitRebase

Git Problem Overview


I'm on master and I did rebase -i <my_branch>

Got this:

noop

# Rebase c947bec..7e259d3 onto c947bec
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x <cmd>, exec <cmd> = Run a shell command <cmd>, and stop if it fails
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

I would like to pick some commits not all as some of them are not welcome. Also how do you work when you want to keep some files or changes always 'local' to some branch? Is there some helper like .gitignore?

Git Solutions


Solution 1 - Git

Like a non-interactive rebase, you have to rebase onto a particular commit.

With a non-interactive rebase, if you supply a direct ancestor of the current commit then you aren't changing anything; with an interactive rebase you can edit commits after the commit that you are rebasing onto, even if the commit is a direct ancestor of your current commit but you do have to specify this commit that you want to edit onwards from.

I don't know the details of your situation but you might want something like this:

# Opportunity to edit or prune commits between origin/master and current branch
git rebase -i origin/master

or

# Edit some of the last ten commits
git rebase -i HEAD~10 # Note that ~10 uses a tilde("~") not a dash("-"_) !

Solution 2 - Git

rebase -i without a commit range will not display any commits. to rebase the last, say, 7 commits use the following:

git rebase -i HEAD~7

be careful though, that this will rewrite history. don't do it, if the commits are already pushed


for your second question: have a branch with your changes (basically a configuration branch) and regularly merge the other branches into it. this way the changes will not move to other branches

Solution 3 - Git

When you're using git rebase -i, you usually have to specify from which commit do you want to perform the rebase. So, if, for example, you want to remove some of the commits among the last 10 to the current branch, you would do:

git rebase -i HEAD~10

Solution 4 - Git

As others have mentioned, you need to specify a commit range.

git rebase -i <latest-commit-to-be-retained>

(Assuming that you are on the same branch as the commit to be edited)--

To specify the commits, you can use the HEAD~5 shorthands or use sha checksum (which you can get by git log)

In fact any commit will do if it is prior/ancestor to the commits which you want to delete/edit/reword in the tree. This will list all the commits since the <latest-commit-to-be-retained> in the editor(defined in your git config). From the list, to delete a commit, just delete that particular line, save and exit (vi habbits :) )the file+editor, and do git rebase --continue

For the second answer, I agree with knittl

> have a branch with your changes (basically a configuration branch) and > regularly merge the other branches into it. this way the changes will > not move to other branches

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLukaszView Question on Stackoverflow
Solution 1 - GitCB BaileyView Answer on Stackoverflow
Solution 2 - GitknittlView Answer on Stackoverflow
Solution 3 - GitsvickView Answer on Stackoverflow
Solution 4 - Git0xc0deView Answer on Stackoverflow