Skip to content

Instantly share code, notes, and snippets.

@jgwill
Last active January 9, 2021 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgwill/b000037b02f942be7796675c96bca4ce to your computer and use it in GitHub Desktop.
Save jgwill/b000037b02f942be7796675c96bca4ce to your computer and use it in GitHub Desktop.
Branch copy-merge strategy for GIT to duplicate file that uses the same source in the repo

Branch copy-merge strategy for GIT to duplicate file that uses the same source in the repo

# I RAN BRANCHING twice with theses two dir with few operation at the end
export targetdir=gia-young-picasso-v05-2101082232
export srcdir1=gia-young-picasso-v05-add
export srcdir2=gia-young-picasso-v03-201216

## BRANCHING
for srcdir in $srcdir1 $srcdir2; do
  export branch_name=dup-$srcdir
  export tmp_new_dir=$srcdir'-new'
  git checkout -b $branch_name
  git mv $srcdir $tmp_new_dir
  git commit  -m "dub:$srcdir"
  git checkout  HEAD~ $srcdir

  git checkout -
  git merge --no-ff $branch_name

  # ---
  git mv $tmp_new_dir/*.jpg $targetdir
  git commit $targetdir -m "migrated:new-branch $srcdir"
  rmdir $tmp_new_dir
  git commit $tmp_new_dir -m cleanup
done

Comparing the workdir and the git repo server storage

# workdir
jgi@as:/a/lib/tmp_clone$ du -ksh libdatasets/
1.9G    libdatasets/

# Git database
jgi@as:/a/lib/tmp$ du -ksh /srv/git/libdatasets.git/
779M    ../git/libdatasets.git/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment