Lets us say I have a file filename
in a git repository in subirectory dir1
with a history something like this:
v7 --- v8 --- v9 --- v10
The file is part of a larger repository with various subdirectories, but only the above changesets affect this file. Now I have dug up an old version of that file (filename
too) that has by mistake been committed to another subdirectory dir2
. This older version only "exists" in one changeset, say:
v4
The problem now is, can I rewrite the history of these (to git) two files so that it appears as if filename
has only existed in dir1
resulting in a history something like this:
v4 --- v7 --- v8 --- v9 --- v10
I guess I could try removing the file in dir2
and committing it as a new version of the file in dir1
, but that will mess up the actual history of the file so that what is actually the oldest version of the file will appear as the newest.
I have very little experience with "tweaking" the history of git repositories, so I do not know how to do this, but I am guessing rebase may be the answer? I am the only one working on the repository, so my only concern will be sync'ing these changes across two computers.
I guess what I want to do is really just leave the file originally in dir2
where it is in the history, but I want to change the commit called v4
above to make the file a version of the file in dir1
.
filename
indir2
, I want it to become a previous version offilename
indir1
(which it really is). I will try your link to see if I understand how to do it from that description, thanks.filename
were indir1
and never indir2
? You will need to go and edit your commitv4
usingrebase -i v4
, choose edit for that particular commit, and then change it.dir2
wasn't a version of the file indir1
, at least not in a linear way. I know Git will usually refuse to make commits that don't include any changes, so some of your conflict resolutions probably made it so that the file didn't change, and git simply eliminated those commits. You might want to redo the rebase, and try to merge changes together for conflicts rather than choose one of the versions.