git-rebase

How do I `git rebase -i` and prevent “You asked to amend the most recent commit, but doing so would make it empty.”?

时间秒杀一切 提交于 2019-11-29 16:37:26
问题 I want to run a git rebase -i some-hash . When I run it, I get the error: You asked to amend the most recent commit, but doing so would make it empty. You can repeat your command with --allow-empty, or you can remove the commit entirely with "git reset HEAD^". [...] Could not apply [...] That error seems specific to a single commit, as --allow-empty isn't an option I can pass to rebase. Apparently --keep-empty IS an option I can pass to git rebase , but it doesn't seem to fix the problem. How

How to rebase after squashing commits in the original branch?

Deadly 提交于 2019-11-29 12:03:30
问题 I have A--B--C master \ D branch0 Then I squash B and C into B' . How do I rebase branch0 such that it looks like this: A--B' master \ D branch0 回答1: Use the --onto argument to git rebase, which changes the baseline that git replays work on. git checkout branch0 At this state you should still see C in your git history. git rebase --onto B' C This translates to: Take all commits in my current branch since commit C (In your case that's just D ) and play back on top of B' You can also use the

Detailed reason why remote git rebase is so evil

a 夏天 提交于 2019-11-29 11:52:12
So I come from a centralized VCS background and am trying to nail down our workflow in Git (new company, young code base). One question I can't find a simple yet detailed answer to is what exactly does rebase on a remote branch do. I understand it rewrites the history, and in general should be limited to local branches only. The workflow I'm currently trying to vet out involves a remote collaboration branch, each dev "owning" one for the purpose of sharing code. (Having 2 developers and max 3 in the foreseeable future a feature branch for each project & feature request seems excessive and more

Undo a git rerere resolution that was done in a rebase

萝らか妹 提交于 2019-11-29 10:57:53
问题 Okay, so I really like the git rerere command. Although, I haven't really used it that much other than letting it auto-magically record my conflicts and resolve them for me. However, I did mess up one of my conflict resolutions during quite a large rebase (rebasing a really stale feature branch with the latest release). feature -> a - b - c - d release -> e - f - g - h rebase/feature -> e - f - g - h - a' - b' - c' - d' So, say for instance that b' has an incorrect merge (thanks to me!), and

How do I reduce the size of a bloated Git repo by non-interactively squashing all commits except for the most recent ones?

早过忘川 提交于 2019-11-29 10:14:40
My Git repo has hundreds of gigabytes of data, say, database backups, so I'm trying to remove old, outdated backups, because they're making everything larger and slower. So I naturally need something that's fast; the faster, the better. How do I squash (or just plain remove) all commits except for the most recent ones, and do so without having to manually squash each one in an interactive rebase ? Specifically, I don't want to have to use git rebase -i --root For example, I have these commits: A .. B .. C ... ... H .. I .. J .. K .. L What I want is this (squashing everything in between A and

Why is git rebase discarding my commits?

喜你入骨 提交于 2019-11-29 10:04:01
I'm trying to rebase a branch on top of master, something I've done a thousand times before. But today, it's not working: > git status On branch mystuff Your branch and 'master' have diverged, and have 6 and 2 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working directory clean > git rebase First, rewinding head to replay your work on top of it... > git status On branch mystuff Your branch is up-to-date with 'master'. Untracked files: (use "git add <file>..." to include in what will be committed) [a directory from the project]

Why is “rebase --onto ABC” different than “rebase ABC”?

余生长醉 提交于 2019-11-29 08:50:25
Using git 2.11, git rebase documentation says: The current branch is reset to <upstream>, or <newbase> if the --onto option was supplied. This has the exact same effect as git reset --hard (or ). ORIG_HEAD is set to point at the tip of the branch before the reset. I understand it as if upstream and newbase points to the same "base reference", then this means the two rebase syntaxes below are equivalent: git rebase ABC git rebase --onto ABC Here is the demo I setup. Let's assume the current branch is FeatureABC it is perfectly in sync with the remote branch. #---create two identical branches,

How to run git rebase interactive mode to remove duplicate commits

限于喜欢 提交于 2019-11-29 07:19:26
I made a mistake when I rebase to a recent commit. ( I forgot to "git fetch --all" first, then rebase), and I've committed and pushed to the remote branch since. Now I did the rebase properly by fetching first, solved the conflicts, and pushed to the remote branch. Now, it seems all my recent commits are showing up twice. What I would like to do is to use git rebase interactive mode, pick all the commits that I want, then rebase properly to the commit sha code. Is this the way to do this? and if I start git rebase -i, which sha code should I use, the original branching point sha code? or the

Git rebase a branch onto master failed, how to resolve?

时光怂恿深爱的人放手 提交于 2019-11-29 06:30:39
问题 I've been working on a local copy of a remote git repo. I created a branch on my local copy, let's call it 'my_branch'. I've committed a few times on my_branch. I recently pushed 'my_branch' to remote. However I didn't know that someone else added a version to the remote master. So, I fetched it to my local master. So...long story short, my local repo looks like this (I'm trying to use the diagraming convention here) . --C0--------------C7-- (local master) \ --C1-C2-C3-- (local my_branch) \ -

Remove an old Git commit from a branch without using a reverse patch? [duplicate]

时光毁灭记忆、已成空白 提交于 2019-11-29 03:02:34
This question already has an answer here: Delete commits from a branch in Git 28 answers I have a master branch like this.. A -- B -- C -- D -- E -- HEAD Is there any command that remove one of a old commit and retain the others, say commit C? finally it becomes like this A -- B -- D -- E -- HEAD I know that we can use a reverse patch and apply a new commit with reverse patch to remove commit C, but the tree structure will not be so clear and looks bulky, i.e. A -- B -- C -- D -- E -- C(apply reverse patch) -- HEAD Anyone knows? Use interactive rebase. For example, to go back 5 commits: git