I am thinking that you are going to want to look at the git log using the following command:
sudo git log
Then, you will want to checkout/revert the hash of a previous commit that was done where you edited a file but not others yet and that is what you want in branch2. To checkout/revert to the old commit use the following command:
sudo git revert THELONGNUMERICHASHCODEGOESHERE
e,g. sudo git revert 102b78f76dcf2302345570b4f738b28700266f87
After you have checkout the commit you want, you can then out the branch into the new branch you want with the following command:
sudo git checkout -b branch2
Moving on to file C, this one might be tricky but you can try:
- Switch back to master:
sudo git checkout master
- Checkout a new branch of master for safety such as:
sudo git checkout master-2
- Merge in
branch1
into master-2
. While on master-2
run: sudo git merge branch1
- Resolve the conflicts in any files listed if any. Do not skip any of them. then add and commit that branch, not push.
- Now, master-2 will have all the changes made on it. If you want you can merge this into master but you mentioned that file B needs to be an older file so I don't think a merge to master is ready.
- You will need to checkout branch1:
sudo git checkout branch1
- Find the previous commit with the correct file
B
using sudo git log
- Use git revert to checkout the older commits as mentioned above. Once you find the once you want, check that out to a new branch using:
sudo git checkout branch-fileb
- Touch (add an extra line, as touch might not register with git) the file B on the newly created branch. Add and commit the change/touch.
- Still on branch
branch-fileb
, merge back in branch1 using sudo git merge branch1
- Resolve the conflicts, and you should have the correct A, B, and C files you want.
- Merge master to prepare while on branch
branch-fileb
using: sudo git merge master
- Resolve all conflicts.
- Switch back to branch
master
, then merge in branch branch-fileb
using: sudo git merge branch-fileb
And the branches should all be how you want them now.
For good housekeeping delete and local unused branched and any unused remote branches.