How can I rewrite history so that all files, except the ones I already moved, are in a subdirectory?

前端 未结 2 1043
野趣味
野趣味 2020-11-30 19:45

I have a project under git. One day I moved all project files from current directory to foo/bar/ under the project. I did it using git mv

2条回答
  •  暖寄归人
    2020-11-30 20:21

    To wrap things up here's a short summary of what I did. The command that worked for me was:

    if [ ! -e foo/bar ]; then mkdir -p foo/bar; git ls-tree --name-only $GIT_COMMIT | grep -v ^foo$ | xargs -I files mv files foo/bar || echo ""; fi
    

    The echo command that I added at the end ensured that even when mv fails entire command will continue running. It didn't move contents of foo/bar/foo, but I can live with that.

    Thanks a lot to Dan Moulding (!!!) and Jefromi for the help.

提交回复
热议问题