0

I have 3 branch -> Master, develop and admit_card. I had created before admit_card from the develop branch. I always made changes on admit_card branch and merge it into develop.

But suddenly I have changed some more files and also deleted folder form the develop branch. And now I want to copy/keep updated to the admit_card branch like develop branch (By deleting folders and files).

I merged it with develop branch. It is merging with develop branch properly. But the issue is the folders and files I deleted from the develop branch is still showing into the admit_card branch.

here is the merge develop branch with admit_card branch.

git checkout admit_card
git merge develop

what should I do please? How can I copy/replace exact develop branch to admit_card branch? Can anybody please help me?

Thank you

Subrata Mondal
  • 822
  • 7
  • 17
  • Try [cherry-pick](https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean) from `develop` to `admit_card` – Subrata Mondal Jul 23 '19 at 13:41
  • @SubrataMondal Thank you for your help. I have tried cherry-pick. But it is showing this error. **error: The following untracked working tree files would be overwritten by merge:** Files..... Aborting fatal: cherry-pick failed after using this command `git checkout admit_card` `git cherry-pick -x develop` – Syed Imran Ertaza Jul 23 '19 at 13:52
  • First `git add .` `git commit -m "Before cherry pick from development"` Into `admit_card`. Then cherry pick – Subrata Mondal Jul 23 '19 at 14:00
  • @SubrataMondal It is showing this message **Performing inexact rename detection: 100% (188544/188544), done. On branch admit_card You are currently cherry-picking commit 5221a7b. nothing to commit, working tree clean The previous cherry-pick is now empty, possibly due to conflict resolution. If you wish to commit it anyway, use: git commit --allow-empty Otherwise, please use 'git reset'** when I am trying to run this code `sudo git cherry-pick develop` – Syed Imran Ertaza Jul 23 '19 at 15:15

1 Answers1

0

I think rebase is better approach here.

On your admit_card branch run

git rebase develop

This will, in effect, set your admit_card branch to the contents of the develop branch and then play back any additional commits on the admit_card branch on top of this. You might have merge conflicts if you have touched the same files in both the branches. Once you resolve the merge conflicts, your admit_card branch will be a clean topic branch on top of your develop branch again.

Run git rebase --abort if you get stuck with the merge to revert back to how things were.

idlethread
  • 1,111
  • 7
  • 16
  • Hi @idlethead, Thank you. But I think, this will replace the commit history too. I can not get back to the older commit, if I use "rebase". right? – Syed Imran Ertaza Jul 25 '19 at 05:20
  • You can, using git reflog. In your question you asked "How can I copy/replace exact develop branch to admit_card branch?" rebase is the answer. You are in this situation because you changed your develop and admit_card branch together - if you'd committed changes from admit_card to develop before you deleted some files there, you wouldn't face these issues. – idlethread Jul 25 '19 at 06:18
  • Hi @idlethead, Thank you for you suggestions. But I committed both admit_cart and develop branch. And for the clearance, yes I want to replace the current status(replace folder, deleting folders and files etc) from develop branch to admit_card branch but admit_card commit history. So that if I need to role back anytime to another commit, I can move to the commit. Hope you understand my issue. Let me know if there is any solution please. Thank you – Syed Imran Ertaza Jul 27 '19 at 03:44
  • You only have two options afaict. Use `git merge` and deal with the merge conflicts or `git rebase` and rewrite branch history on admit_card. In both cases, `git reflog` will allow you got go back to an older version. You can even tag the current state of the two branches to make it easier to checkout the original versions at a later time. – idlethread Jul 27 '19 at 12:34