You can watch the youtube video explaining and demoing this topic here.
Introduction
In a previous blogpost, we learned how to make a Pull Request on bitbucket using the branching method. Sometimes after making a pull request on a code repository, you get feedback that some things in your pull request need to be changed before it will be merged.
It's not good to create a brand new pull request for your changes, because then you'll lose the comments, and it'll keep making the PR numbers go up. You should edit the current pull request. You can do that by overwriting the old commits for that PR and then pushing over the current branch. Let's see how to do that. Editing A Pull Request (And Git Squashing)
If you already have a pull request, and you want to make some changes to the code for it, you can do so by downloading your version of the project, making the changes, squashing the commits together, and then pushing back to the origin, overwriting your old branch.
The list of steps is as follows:
1. On bitbucket, look for the source code for your branch.
2. Clone the project at the commit you want to change.
git clone repolinkhere
Note that you want your repository link to be for the specific commit that you worked on for your PR's branch. (See video for tips and tricks about how to get this URL.)
3. In that local project, checkout onto the branch your Pull Request is for.
git checkout yourbranchname
4. Make the changes to the project (on your local computer).
5. Add and commit those changes. (You can do this as many times as necessary.) 5.5 If you want, you can just push all of those commits straight to the repository with "git push". (But then you might have a lot of excessive commits in your git history. The following steps will allow you to trim the commits down if you think you have too many.)
6. Squash your recent commits with your previous commits that were originally in your PR. The following command will do that.
git reset --soft HEAD~2
NOTE: That "2" will change depending on the number of commits you're squashing together. The number you should use is [the number of commits in your PR] + [the number of commits you've recently made locally]. You can check bitbucket to see the first one, and you can use the "git status" command to see the second one. See the video for an example.
7. Next, commit your new change.
git commit -m "New message for the total PR."
Of course, change the message in the quotation marks to describe your pull request.
8. Push your new commit to the branch.
git push origin +yourbranchname
Change the 'yourbranchname' to the name of the branch for your Pull Request. DO NOT remove that + sign. That + sign is going to overwrite your old branch (that should have the same name).
Since this process overwrites your old commits, the effect is that this updates the code for your existing Pull Request. So now, you can go back to the Pull Request on bitbucket, make a comment about the changes, and edit the Pull Request description to update what your new code actually does.
Conclusion
Using the "branching" technique for Pull Requests and this "squashing" technique, you can edit pull requests and have an easy process making changes to your bitbucket projects.
Bookmark this page so you have the steps and commands ready whenever you need it.
Like this content and want more? Feel free to look around and find another blog post that interests you. You can also contact me through one of the various social media channels.
Twitter: @srcmake Discord: srcmake#3644 Youtube: srcmake Twitch: www.twitch.tv/srcmake Github: srcmake
References
1. Squashing git commits. Comments are closed.
|
AuthorHi, I'm srcmake. I play video games and develop software. Pro-tip: Click the "DIRECTORY" button in the menu to find a list of blog posts.
License: All code and instructions are provided under the MIT License.
|