Remove directory in hierarchy while preserving status in git
I have a repository like
/file1
/file2
/dir_a/file3
/dir_a/file4
...
how can I remove dir_a
and move all its content one directory up (in this case to /
) while keeping the status of all files (untracked, changed but not staged), which may be contained in /
but also in dir_a开发者_如何学Go
?
git-mv
should be able to handle this. Use git mv -k dir_a/* .
, and the staged/unstaged status will be preserved. This will not move untracked files, so use mv dir_a/* .
afterwards.
# shelving unstaged stuff
git stash
# moving content from /dir_a to /
# that should suffice as git doesn't track directories but only files
git status -uno -s | grep "src_dir" | awk '{print "-n " $2 " dest_dir"}' | xargs -n3 git mv -f
# than move what remains in source dir manually:
mv src_dir/* dest_dir
# resurrect unstaged changes
git stash pop
Second line could be better but it worked for me.
精彩评论