简体   繁体   中英

Git - ignoring a single commit

I had branch A that contained a lot of code and to facilitate merging it, I had to scrape off one big feature - that is, I created a commit deleting some of the new files I created. Thus creating branch B. B got merged to develop, and develop branch piled up some more changes.

Now I want to revisit branch A and merge develop into it. Scraping off was in a single commit. So I would like to

git fetch origin develop

and merge all commits but a certain commit (I merged all commits up to the deleting commit, but I also want to merge all the commits after that deleting commit [there are no expected conflicts]).

To sum up:

B = A + (deleting commit)

develop = B + commit1 + commit2 + ... + commit[n]

I want to create:

A' = develop - deleting commit

Is there a way to create a negating commit and maybe stash that? Then I can git pull origin develop & git stash pop .

How can I do this?

Let's say that you have branches A , B , and develop in your local git repository. In order to have develop contain all commits except the large-scale deleting commit, do the following:

git checkout develop
git rebase -i A

You will then get a screen that gives you a list of all your commits since the head of branch A . Delete the line with the commit you don't want, and then save the file (usually the interface is in vi , so entering :wq will save and quit. Check out vi documentation for more details). Once you've done that, the develop branch will now have all the commits except the big deletion. Don't worry, though, because B will still have the delete commit, and you can always go back to it by checking out branch B if you want.

Caveats: you may end up with some conflict or other as a result of doing these operations. Also, there is no guarantee that you code will actually work; git is a text tool, not a "code" tool per-se.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM