Domanda

Lets say I have 3 git commits:

  1. Commit changes on sidebar
  2. Commit changes on footer
  3. Commit changes on header

Now lets assume I have went trough spiritual awakening and realized that only changes I need is on the header and one the sidebar, the footer was fine and did not needed to be changed.

Is there a command that would do the following?:

  • merge commit#3 minus commit#2
  • delete commit#2
  • merge commit#3 plus commit#1

(or any other method that makes commit#2 as it never happened).

È stato utile?

Soluzione 2

You can always just revert the changes from a single commit using git-revert.

Given one or more existing commits, revert the changes that the related patches introduce, and record some new commits that record them. This requires your working tree to be clean (no modifications from the HEAD commit).

Note: git revert is used to record some new commits to reverse the effect of some earlier commits (often only a faulty one). If you want to throw away all uncommitted changes in your working directory, you should see git-reset(1), particularly the --hard option. If you want to extract specific files as they were in another commit, you should see git-checkout(1), specifically the git checkout <commit> -- <filename> syntax. Take care with these alternatives as both will discard uncommitted changes in your working directory.

So:

git revert <commit-id-of-footer-changes>

Altri suggerimenti

Interactive rebase allows you to modify, rearrange, merge commits, change messages and more:

git rebase --interactive

citing the help:

# 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, exec = run command (the rest of the line) using shell
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#

Losing the commit is what you want.

You could use cherry-pick to merge in the commits you want and then revert the development branch to commit before footer change.

git checkout branch_to_merge_into
git cherry-pick commit#1 commit#3
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top