jaeseeker.blogg.se

Git create branch but delete history
Git create branch but delete history







NET project, it’s usually the contents of the bin and obj directories (wherever they’re located) and the packages directory (usually at the root of the solution). So, assuming the branch we want to cleanup is master, let’s create a master2 working branch:īefore we start to cleanup, we need to identify what needs to be cleaned up. The easiest way to avoid causing damage to the original branch is, of course, to work on a separate branch. Since we’re going to make pretty drastic and possibly risky changes on the repo, we’d better be cautious. But don’t do this on a branch your colleagues are currently working on, unless you want them to hate you 😉.

git create branch but delete history

In my case, it didn’t matter, because I didn’t need to publish the rewritten branch (I just wanted to examine it locally). If someone else bases works on the existing branch and the branch has its history rewritten, it will become much harder to integrate their commits into the rewritten branch. The operation we need to perform here involves rewriting the history of the branch, so a warning is in order: never rewrite the history of a branch that is published and shared with other people. Let’s see step by step how this can be achieved.

git create branch but delete history

This made the history hard to follow, because each commit had hundreds of modified files.įortunately, it’s rather easy with Git to cleanup a branch, by recreating the same commits without the files that shouldn’t have been there in the first place. gitignore file, so a lot of useless files (bin/obj/packages directories…) had been commited. Unfortunately, the repo had been created without a. In any cloned repositories, to do a “forceful” pull, run the following commands.I recently had to work with a Git repository whose modifications needed to be ported to another repo. We can make Git forcefully resetting the cloned repositories too.

#GIT CREATE BRANCH BUT DELETE HISTORY UPDATE#

One consequence of clearing (or changing) history of a Git repository is that we have to forcefully update other cloned repositories which contain the old Git history. Git gc -aggressive -prune=all # remove the old files Reset other existing Git repository clones after the branch is cleared git branch -set-upstream-to=origin/master master # Local master tracks origin/master We can add the remote master branch tracking and do a garbage collection in the operating repository as follows. The repository we are operating has the new branch metadata and some garbage files. Git push -f origin master # Force push master branch to Git server Book keeping in the operating Git repository clone Git branch -m master # Rename the current branch to master Git branch -D master # Deletes the master branch Git add -A # Add all files and commit them git checkout -orphan tmp-master # create a temporary branch The commands are as follows, operating in a cloned repository. force push the master branch to the Git serverīecause the new master branch has only one commit, after the master branch is force pushed to the Git server, the master branch’s history is “cleared”.rename the temporary branch to be the master branch.add all files into the temporary branch and commit.

git create branch but delete history

To clear the history of the master branch, we can do the operations of:

  • Reset other existing Git repository clones after the branch is cleared.
  • Book keeping in the operating Git repository clone.
  • Clear Git master branch history in the Git server.






  • Git create branch but delete history