Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6472521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:21:16+00:00 2026-05-25T06:21:16+00:00

We have the following history start master public | | | v v v

  • 0

We have the following history

start         master  public
|                 |   |
v                 v   v
o---o-- ... --o---o---o

Unfortunately we made some commits into the master branch containing some sensitive data. We amended this in a separate branch called public. Now we want to “cut-off” the public branch in order get a complete and clean “state” in public but without the compromising history parts still contained via master. In other words we want the following new history:

start         master
|                 |
v                 v
o---o-- ... --o---o
 \
  o <- public

Now checking out public shall lead to the same working tree as in the original situation but without the sensible history details. Afterwards we mothball the old master branch: Rename it to unsafe and elaborate a new master branch out of the new public branch. This way we conserve the old history in unsafe and are able to push the public branch into the public without any worries:

start         unsafe
|                 |
v                 v
o---o-- ... --o---o
 \
  o---o-- ... --o <-- public
   \           /
    o-- .. --o-- ... --o <-- master

What are the right git commands to achieve this?

PS: Of course we could checkout start, make a new branch and commit there the entire working tree of the public branch. But there must be a different, fancier, git way!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:21:17+00:00Added an answer on May 25, 2026 at 6:21 am

    The proper way to merge all commits in public into one commit (i.e. merging several commits to one, or removing individual commits entirely, etc.) is to use git rebase -i. So what you would do is (assuming the first commit has a tag start as your graph indicates):

    git checkout public
    git rebase -i start
    

    An editor window comes up where you can edit the order of all the patches
    simply use squash for all your patches. After you saved that file and closed the editor, git will recombine your patch history as requested. Of course, the master branch will not change its history at all.

    To rename your current master as unsafe and start all further development on public, I would do:

    git checkout -b unsafe master # <- creates a new branch "unsafe"
    git checkout master
    git reset --hard public    # <- forces master branch to point to public
    

    If you don’t create the unsafe branch, the hard reset will loose all commits in master and you won’t be able to (easily) access them any more. So make sure you really created that branch.

    An alternative would be to rename master to unsafe and then create a new master branch:

    git branch -m master unsafe  # renames master to unsafe
    git checkout -b master public  # creates new branch master as a copy of public
    

    Both should result in the exact same branch structure. (Granted, the second does not have that danger of loosing the history…)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data in a table in following manner tablename : history page_url verified
I have following ternary statement: $.history.init(function(url) { load(url == ? #some-page : url); });
In my git repository, I have merged branch B into master, getting the the
Assume I have a branch with the following history: A - B - C
I'm using Oracle 10.2 and have the following query: select h.company, count(*) from history
I have following plist: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE plist PUBLIC -//Apple//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
i have the following code using Nhibernate.Linq var apps = Session.Linq<History>().OrderByDescending(r => r.LastUpdated).Take(50); Console.Write(apps.Count());
Say I have the following table (where History is an xml column): Id Value
I have the following SVN structure: iPhone -> Project A -> trunk, branch, tags
I have a following LINQ-to-entities query IQueryable<History<T>> GetFirstOperationsForEveryId<T> (IQueryable<History<T>> ItemHistory) { var q =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.