I have a feature branch, let's call it A, and a main line, let's call it B, where we deliver. The problem is the following:
- Branch A was many commits ahead of branch B, nothing extraordinary so far. So I did a merge from branch A to B.
- Then I noticed, this is not what I wanted as I suspect the automatic merges were not alright.
- I did a revert for the merge, which was ok, the changes merged disappeared.
- I only want to have the code state of branch A in branch B; consequently, I removed the directories and files locally in branch B and wanted to do the merge from branch A again, which does not work anymore as git perceives that the merge has already been done. My second idea is to check out branch A in branch B but I don't know how as normal checkouts from the remote repository will go into the corresponding branches: A in A and B in B.
Any idea how I could check out branch A in branch B? Remark: there are no changes in the main line since starting this feature branch A, so what I need is A in branch B. Thanks for any solutions in advance.
Would git fetch <remote> <remoteBranch>:<localBranch>
do this?
git fetch origin A:B
git push origin B
Solution: See the answer from VonC and also my questions about the index. Thanks for all responses.
cd /path/to/repo
git switch B
git restore -s A -SW -- .
git commit -m "override B with A content"