How to remove changes to unwanted file in a branch that was modified in another branch in git


How to remove changes to unwanted file in a branch that was modified in another branch in git



I created a local branch named branch1, made changes to file "filename1" (made changes to method "method1") and pushed those changes to git and created a pull request. After that i created another branch locally named "branch2" made changes to same file "filename1" as in branch1 but other changes not related method1 and pushed those changes to git and created a pull request. Now the question is in this pull request created for branch2 i have changes included to filename1 changes made in branch1. i don't want to see those changes added here in this branch2. how can i do it. thanks.



Edited:
branch1 - changes to filename1 ...pushed to git
branch2 - changes to filename1 ...pushed to git
I pushed the changes in branch2 to git and i see changes to filename1 made in branch1. I do not want to have those changes in branch2. How could i do that?





this is too confusing try rephrasing
– Count
Jul 3 at 9:23




1 Answer
1



This sounds like you created "branch2" without leaving "branch1" first.

@Next time: To accomplish what you want:


git checkout -b branch1


git push --set-upstream origin branch1


git checkout master


git checkout -b branch2


git push --set-upstream origin branch2



@Current pull-request:
Assuming changes to the pull-request aren't tracked, you could delete your local branch2, recreate branch2 as described above, cherry-pick the commits you need from the current remote-branch2 (or use rebase, see cmbuckleys comment) and then force push this over remote-branch2.



If changes to the pull-request are tracked by whatever is hosting your git repository, there is no way to completely make them vanish from the log I'm aware of. You could only close the pull-request and create a new one.



This is all based on the assumption that you don't have any influence on the main repository you created a pull-request for.





Yes i modified the files staying in branch1 and created branch2 and commited those changes. could you please suggest the commands to acheive desired result.thanks.
– swathi
Jul 3 at 9:28





You could also use git checkout branch2; git rebase --onto base-branch branch1, where base-branch is where you wanted to fork from originally.
– cmbuckley
Jul 3 at 9:31


git checkout branch2; git rebase --onto base-branch branch1


base-branch





This would indeed be cleaner than cherry-picking, yes. Are you aware of any way we could even circumvent the forced push (beside creating a new pull-request)?
– Fabian N.
Jul 3 at 9:36






what should the base-branch be in this case?
– swathi
Jul 3 at 9:46





The branch you were on before creating branch1 (most likely master).
– Fabian N.
Jul 3 at 9:49







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

Display dokan vendor name on Woocommerce single product pages