markdown Git:移动保存历史记录的子文件夹中的文件

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Git:移动保存历史记录的子文件夹中的文件相关的知识,希望对你有一定的参考价值。

# Change structure of project folder with Git

### I have this structure:

     project-folder/
         .git
         wp-admin/
         wp-content/
         wp-includes/
        .htaccess
        ...

### I want this structure:

     project-folder/
         .git
         public
              wp-admin/
              wp-content/
              wp-includes/
             .htaccess
             ...

### The benefits
* Keep away from the Internet my `.git` folder
* Wordpress files separated in a sub-folder
* Keep Git history changes
* Hide from the Internet deployment scripts or project sensitive informations


## Move files with git and keep file history


1. Be sure you don't have files uncommitted, if not commit them before next step.

    `git status`


2. In project-directory create `public` subfolder

    `mkdir public`

3. Move files with `git mv` except `public` subfolder to avoid errors

     `for file in $(ls | grep -v '^public$'); do git mv $file public; done;`

4. Move specific files like .htaccess etc...

     `git mv .htaccess public/`

5. Commit changes

     `git commit -m 'Moved files to public/'`

6. That's all !

     `git log -M summary`


## To see file history of moved files
### In Bash:
`git log --follow`

[http://git-scm.com/docs/git-log](http://git-scm.com/docs/git-log)

### In SourceTree:
On logging file(s) you have to check `[x] Follow renamed files`

以上是关于markdown Git:移动保存历史记录的子文件夹中的文件的主要内容,如果未能解决你的问题,请参考以下文章

markdown Git删除我们的所有提交历史记录

markdown GitHub - 使用git命令删除提交历史记录

为啥 git log 可能不显示移动文件的历史记录,我该怎么办?

如何 git 将文件夹和文件移动到新文件夹并保留历史记录? [复制]

text git实用程序用于移动/重命名文件或文件夹并使用它保留历史记录。

如何将文件从一个文件夹移动到同一git存储库中的另一个文件夹保留历史记录[重复]