I've created a rails website for client X. I now have a client, Y, who wants a website that does the exact same thing as client X, but with a different skin.
I made a git branch from clientXcode and called it clientYcode. I then did all the changes to the views to make it look different, and lala, the same website with a different skin.
Now here's what I don't understand about git: I've made many changes to clientXcode in the views, models, and controllers; and now I want to merge those changes into clientYcode, excluding any view changes. Since views, models, and controllers each have their own folder in rails I was hoping to be able to do something like:
git merge client_x_code 'app/controllers/*', 'app/models/*'
QUESTION 1: Is something like that possible with git? If so, how would I do it?
QUESTION 2: Was branching the best solution to make a copy of my project?
Well I found the easiest solution to my problem...
git checkout clientYcode
git checkout clientXcode "app/controllers/"
git checkout clientXcode "app/models/"
And that does what I want!
The simplest course of action is to merge everything, except the content of the directory you want to keep.
You can do that by adding a merge driver in that directory, as the How do I tell git to always select my local version for conflicted merges on a specific file? question details.
With that merge driver in place, Branching is a good solution in this case.
Extract:
We have a .gitattributes file defined in the dirWithCopyMerge directory (defined only in the branch where the merge will occurs: myBranch), and we have a .git\config file which now contains a merge driver.
[merge "keepMine"]
name = always keep mine during merge
driver = keepMine.sh %O %A %B
Related
I want to find the parent branches for a particular branch. Suppose I have created A branch from master and branch B from A. Now I want to find the parents for B like B->A->Master. I checked the Bitbucket API but there is no such a method available. When I pull the data for a branch there is no field which shows the parent branch details.
You can use regular git commands for that:
git branch --merged HEAD --sort=authordate
This lists the ancestor branches of the current working directory in chronological order (you can of course specify any other ref instead of HEAD) and would be great to use in a script or some automated tooling.
A very quick and dirty alternative way would be to just look at the regular output of git log:
git log --graph --decorate | egrep 'commit .* \('
This variation would maybe be interesting for a human to watch but too noisy for a script.
I have Two change sets in TFS (for a single file) , for example 8901 and 9053.
I want to merge the code in both these change sets.
When I select both the change sets, I don't find any option except compare and copy. Please refer below screenshot of the same.
I want to merge these two changesets so that I the file will finally contain both the versions of code.
Any suggestions on how to achieve this? Please help.
Thanks in Advance.
Merge is using between branches, not between changesets.
It seems 9053 is the latest version of your project, so you should have get this version in your workspace. In my example, it's TestCaseProject.
Then you can try to create a branch for this project from 8901, named TestCaseProject-branch:
After that, perform a merge from TestCaseProject to TestCaseProject-branch, and you can check whether TestCaseProject-branch includes all changes you need in 8901 and 9053.
I am working on a project that contains multiples files with same file name. I am using git to maintain local versions of my changes. After staging the modified files, I notice that files with same name are appearing with status "R" implying replacing one file with another of same name but in different directory tree. How to make sure both are committed without being replaced by one another. I could not find relevant help material regarding this in any of git documentation.
Since this is a proprietary code, I am pasting only sample directory structure:
M <Proj_Root_Folder>/<dirA>/<dirAA>/file1.h
M <Proj_Root_Folder>/<dirA>/<dirAA>/file2.h
M <Proj_Root_Folder>/<dirA>/<dirAA>/file3.h
R <Proj_Root_Folder>/<dirB>/<dirBA>/file4.h -> <Proj_Root_Folder>/<dirA>/<dirAA>/file4.h
In git "R" means "rename". Git thinks that ///file4.h is a file that has been moved from where it was originally. Most likely because the file looks simmer.
I have 2 separate solutions in TFS, the structure is shown below:
App.A1
App.A1.Web
App.A2
App.A2.Core
App.A2.Web
Now I want to merge it to one solution. Additionally, I want App.A2.Core to became common Core project for 2 Web projects, so finally it should look like below:
App.B
App.B.Core
App.B.A1.Web
App.B.A2.Web
I'm using TFS. How it should be done not to loose history ?
Are the following steps:
Creating App.B solution folder in Source Control
Branching App.A1.Web, App.A2.Web and App.A2.Core to this folder
Changing names App.A1.Web -> App.B.A1.Web, App.A2.Web -> App.B.A2.Web, App.A2.Core -> App.B.Core
a good solution ?
Renaming and moving files in TFS2010 will disconnect the history but not lose it.
So, if I move file X in folder A to folder B then the history of X starts again in B. It will however still be in A (if you switch on the ability to see deleted files) where you can view the full history of X.
Similar story if you rename file X to be Y. The history of Y starts, the "deleted" X still has full history.
What this means for you is that the history is never lost.
As for what you want to do here's what I'd do:
Repurpose the App.A1 solution as App.B solution
Move all the App.A2 projects to be with the App.A1/B solution
Delete the App.A2 solution
Copy folders between Team Projects LOCALLY (e.g. xcopy D:\foo\TeamProjectA\Blah D:\foo\TeamProjectB\Blah)
Add D:\foo\TeamProjectB\Blah to $/TeamProjectB.
Make $/TeamProjectA/Blah a Branch - does not have hierarchy.
Make $/TeamProjectB/Blah a Branch - does not have hierarchy.
How do I set the parent of TeamProjecB/Blah to TeamProjectA/Blah?
*EDIT * 2010-12-31
What about editing the DB directly?
That is not possible. You need to do a baseless merge if you want to achieve a merge between the two. But the branch relationship cannot be set.