We have created 20+ code files, each of which is a branch or improvement to the first code. They can be sorted by date, so that to see which file is the file to initialize a git repo. How can I merge those files to one automatically, is there a method to do that or do one has to init a git repo and continue by hand manipulation/commits? File names can be used as a git commit comment. I've searched but couldn't find a post. I'm sorry if that's a repost.
Asked
Active
Viewed 54 times
0
-
I am no expert with git, but that does seem to me like you want to use a screwdriver on nails. [This](https://stackoverflow.com/questions/9862173/git-merging-changes-from-one-file-to-another-files-within-the-same-branch) might help you. // The only way I can think of enforcing a merge of two new files would be to create two (one) branches with two versions of the same file on each. Afterwards merge both branches. But I am pretty sure that will lead to a manual merge. – P. Siehr Jul 03 '17 at 15:10
-
Do you mean that the changes are cumulative, or each file is a distinct set of changes to the original? Do you want to preserve some particular history that shows you progressing through each of these files in some way, or do you just want a version of the file that combines changes from multiple of the original files? – Mark Adelsberger Jul 03 '17 at 15:16
-
It seems all the branches store the same code for different versions and you want to get the latest version of your code. If it's your requirement, git merge is not a good way since merge conflicts can't be solved automatically by modified time between two branches. You can use `gitk --all` to view your commit history and find which branch is your need and then deleted other old versioned branches. BTW: you'd better manage the versions of same code in a certain branch and it will make the history more clear. – Marina Liu Jul 04 '17 at 07:21
1 Answers
0
well...... if all files are a version (thought of as a branch) starting from the "main" file... assuming that main file is called "main.txt", I would do something like this:
- add main.txt into master
- for every file (other than main.txt) I will create a branch (with the name of the file in question) and I will replace main.txt with it.
In the end of the process you will end up with all those branches that you can then rename to something "meaningful" and then you will be able to merge stuff or do whatever you please. so....
git add main.txt
git commit -m "common ancestor for all branches"
ls -1 | grep -v main.txt | while read file; do git checkout -b $file master; mv $file main.txt; git add main.txt; git commit -m "Committing main.txt from $file"; done
That should do.

eftshift0
- 26,375
- 3
- 36
- 60