Is there a way to prevent a silly mistake such as rebasing master onto another branch?
It might be possible to undo this by using the reflog, but I would like to avoid the hassle by preventing the rebase in the first place.
You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called. You can run git rebase --skip to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included.
If you prefer to skip this patch, run "git rebase --skip" instead. To check out the original branch and stop rebasing, run "git rebase --abort".
If you use pull requests as part of your code review process, you need to avoid using git rebase after creating the pull request. As soon as you make the pull request, other developers will be looking at your commits, which means that it's a public branch.
git rebase origin/master will merge in the requested branch ( origin/master in this case) and apply the commits that you have made locally to the top of the history without creating a merge commit (assuming there were no conflicts).
This gist shows how to use a pre-rebase
hook to avoid git rebases the way you want.
https://gist.github.com/uasi/9384329
You would just have to previously configure which branches you want to avoid rebasing through git config
There is a pre-rebase
git hook:
pre-rebase
This hook is called by git rebase and can be used to prevent a branch
from getting rebased. The hook may be called with one or two
parameters. The first parameter is the upstream from which the series
was forked. The second parameter is the branch being rebased, and is
not set when rebasing the current branch.
You could probably use this to implement the functionality you're asking about.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With