Monday, February 8, 2016

Move directory in one git repository to another repository

I've been looking for a way to move a directory in a git repository to a new repository and preserve the history. We are reorganizing some code at work so that's what prompted me to start looking. The scenario is I have a repository and structure that looks like the following:

repoA/
 file1
 file2
 file3
 directory1/
  file1a
  file1b
  file1c
 directory2/
  file2a
  file2b

I want to move directory1 and all of the files in that directory(file1a, file1b, file1c) to a new git repository and preserve the change history. I want to end up with the following:

repoB/
 directory1/
  file1a
  file1b
  file1c

The solution is here. I started with this solution but with the second solution I ended up with the files from my directory1 in the root of the repo. By the time I moved the files into a new directory1 the change history was stored in the root directory of the new repo so if I was in directory1 in repoB I would need to type git log --follow file1a to actually get the full history. Not a big deal but with the first solution listed my directory structure follows, so no need to git mv the files, AND my change log is with the file in the new repo and directory.

Get PID from running process


pgrep -f processname(i.e. vim, emacs, postgres, etc.)