![]() Case 1: Delete the last commitĭeleting the last commit is the easiest case. Others prefer doing such rewritings themselves. There are maintainers that do not allow any rewriting in general and block any non-fast-forward pushes. In open-source projects, always contact the repository maintainer first before doing any history rewriting. to fetch some pull requests on top of the old history. For example you can still cherry-pick commits between the histories, e.g. Yes, you should avoid rewriting history which already passed into other forks if possible, but the world does not end if you do nevertheless. I recently also had to rewrite a large git repository to get rid of some corruption in an early commit that started causing more and more problems. I usually also do a lot of very heavy history rewriting when converting some repository from Subversion or Mercurial over to Git, be it to enforce internal LF line endings, fixing committer names and email addresses or to completely delete some large folders from all revisions. Be it because of leaked sensitive information, to get rid of some very large files that should not have been there in the first place, or just because you want a clean history (I certainly do). ![]() However, sometimes you do want to rewrite the history. If other users are referencing commits in the future of your newly created view of the code-base, they will have some serious work on their hands if they need to merge changes already completed in their local repositories. Your new version of history cannot be pulled like would normally be the case. ![]() You should generally avoid history rewriting for this reason. Especially if it is highly active and people rely on staying up to date. It should be noted that rewriting history can wreak havoc on other users if you have a very large developer base all referencing your repository. Git will handle the rest: $ git revert 7c63649 To do this simple specify the revert command, noting the hash of the commit you wish to undo. Reverting a commit means to create a new commit, that undoes all changes made in the commit you are reverting.Īs with option 1, your history will remain intact. This is a good alternative to the first option above, when you just need to do a bulk undo of the previously (or at any point in the past) committed changes. If you need to back out every single change in all files in a single commit, you can do this easily by executing a revert. This way your original (bad) commit will remain but you will have a complete history. ![]() This is the easiest (and non-destructive) way to correct an error, and should suffice in most cases. If you need to keep the history of your repository intact, you basically have two options (with a third workaround): Option 1: Update your repository with a new commitįor a simple correction in one, or even a handful, of file, simply remove or fix the bad file(s) in a new commit and push it to the remote repository. But you should do it rather fast before anyone fetches the bad commits, or you won't be very popular with them for a while ) So you've just pushed your local branch to a remote branch, but then realized that one of the commits should not be there, or that there was some unacceptable typo in it. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |