1

I am working on a branch of git which has two files A.c and B.c.

I was creating patches which had changes made to both A.c and B.c

But Now I want all the changes made to B.c to be isolated from this branch and be created as a different branch, this branch should also have all the history of B.c.

This looks like an obvious use case as we may decide in the middle that B.c is a much critical file so needs a different branch, as some one else may need to work on it.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
raja
  • 21
  • 3
  • 1
    Branches in Git are usually repository-level - that is, you don't usually create a separate branch just to track history for a particular file. – Amber Mar 12 '12 at 06:47
  • I mean I want to create a separate branch that contains B.c and it should also have the history of the file – raja Mar 12 '12 at 11:14
  • I don't understand why do you need that. Why would a “critical file” need its own branch? – svick Mar 12 '12 at 13:15
  • So that someone else can take over its development and it has been added by mistake, no needs to be seperated and at the same time history needs to be retained – raja Mar 12 '12 at 16:40
  • git reset HEAD^, unstage files corresponding to HEAD^, x.c and y.c correspond to files of HEAD^, git reset HEAD x.c y.c (this will remove x.c and y.c from index of HEAD),git add A.c, git commit , here add a line Change ID: , this will create a branch that has only A.c , Do similar things for creating branch which has only B.c (similar but not same steps) – raja Mar 13 '12 at 11:28

1 Answers1

0

Assuming you have already committed A.c and B.c, you can:

The end result is a new branch with only B.c patch, and the full history of B.c.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250