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 6820273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:24:18+00:00 2026-05-26T21:24:18+00:00

In master I have some files that should better live in a feature branch.

  • 0

In master I have some files that should better live in a feature branch. I’d like to create such a branch and have the files there, at the same time removing them from master.

I’m not concerned about history, i.e., the files need not to be removed from previous commits. When I do

$ git ls-files
stay.txt
move.txt

$ git checkout -b feature
Switched to a new branch 'feature'

$ git checkout master
Switched to branch 'master'

$ git rm move.txt

the situation in the HEAD is much like I want it. However I’ll run into problems, when I want to merge master to feature. Do I have to deal with it or is there a solution for such a scenario?

  • 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-26T21:24:19+00:00Added an answer on May 26, 2026 at 9:24 pm

    Indeed, if you do things that way, when you will merge those two branches (master & feature), the commit in which you deleted your files will be applied to feature, thus deleting the files that you tried to keep safe in feature.

    Moreover, if you modify those files in feature after deleting it in master, during the merge, the files will be deleted and then modified, creating a conflict :

    CONFLICT (modify/delete): test.txt deleted in HEAD and modified in
    feature. Version feature of test.txt left in tree. Automatic merge
    failed; fix conflicts and then commit the result.

    If the files are not modified (no conflict), you can solve this after the merge by reverting the deleting commit :

    $ git merge feature # in master
    $ git revert SHA-of-the-commit-deleting-your-file
    

    You would get all the commits of the feature and master branches without losing your files.

    However, if there is a conflict, you might have to solve this manually (unless someone finds the perfect git command for this!) :

    $ git merge feature # in master
    $ git mergetool # use modified versions of files
    $ git commit -m "Merge with deleted files solved"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a branch called experiment. git checkout master echo 'some changes' > a.txt
We have some files on our website that users of our software can download.
I have a bunch of ZIP files that are in desperate need of some
I have some pages that use the master page and apply a theme. Some
I'm having trouble with caching on my website. I have static files that should
I have logo in H1 tags on my master page. Now I have some
I have two branches master and exp i tried to cherry pick some of
I have master branch of the project. Then I want to add a new
Somehow my master and my origin/master branch have diverged. I actually don't want them
I have a project that references a number of open source libraries, some new,

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.