nus-cs2103-AY2021S2 / forum

10 stars 0 forks source link

Unable to create PR for a new feature #275

Closed danielonges closed 3 years ago

danielonges commented 3 years ago

I faced this issue while trying to create a PR from my feature branch for a new feature just now. Here are our team repo's PRs for reference: https://github.com/AY2021S2-CS2103-T14-4/tp/pulls?q=is%3Apr+is%3Aclosed

Basically, I created a PR to the team repo in the afternoon (#174 on our team repo), which somehow automatically merged itself into the v1.3 branch that we were working on even without passing any CI. As such, I reverted that PR (#175), and proceeded to re-create the same PR into our team repo again (#176). However from #176 onwards, the feature that I implemented disappeared, and I have not been able to make a PR because it says that no changes have occured (see pic):

image

However, there are clearly different pieces of code in both repos, notably the DoTodayCommand.java file:

v1.3 (team repo): image

daily-task-feature (forked repo): image

I don't know why this is the case. Would really appreciate if anyone could help, thanks!

kouyk commented 3 years ago

The way git works is not simply to see the difference between the heads of the different branches to be merged, to put it in a simplified way, it will find the commits on the feature branch you're trying to merge that isn't available on the v1.3 branch of your team repo. The difference in commits and use those difference to generate the list of files that has changed. In this case, upon the first merge of PR no. 174, all the commits on your feature branch are now a part of the team repo's v1.3 branch. By performing a git revert, it does not actually remove those commits, it creates a set of changes that negates the changes introduced by the merging of PR no. 174. It is done this way to preserve history and forward-moving, thus there is no rewrite of public history.

Back to the question as to why you can't create a PR on the same feature branch, it is because there's no commits on the feature branch that isn't on the v1.3 branch of your team repo. To be able to reintroduce those changes, you need to revert the revert. Yes it sounds confusing but you need to create a PR that reverts PR no. 175 instead.

Edit: Just realised your team has a different workflow that merges to a separate v1.3 branch instead of master, be sure to protect that branch too to prevent accidental mergers.

danielonges commented 3 years ago

Hi @kouyk, thank you very much for the detailed explanation! It really helped to clear the confusion, and I have a better understanding of how git works now 😊

I followed your advice and tried to revert the revert; however, my team has already merged pull requests after #175. Thus, I get this error when I try to revert it:

image

Is there perhaps any way to manually perform this revert of the revert? Once again, really appreciate your help! :)

kouyk commented 3 years ago

An automatic git revert cannot be perform because of merge conflicts due to the newer commits. In this case, you can just branch from v1.3 and perform the git revert locally and resolve the merge conflicts to complete the revert. I'm not familiar with sourcetree so I can only provide you with the command to perform the revert: git revert 3076a606, in the case that you aren't familiar with using git via CLI, there's hints after entering the above command on what you should do to complete the revert.

danielonges commented 3 years ago

Thanks for all the help @kouyk! The command worked great :)