Is it possible to move/rename files in Git and maintain their history?

前端 未结 14 2183
梦如初夏
梦如初夏 2020-11-22 04:42

I would like to rename/move a project subtree in Git moving it from

/project/xyz

to

/components/xyz

If I

14条回答
  •  广开言路
    2020-11-22 05:29

    Simply move the file and stage with:

    git add .
    

    Before commit you can check the status:

    git status
    

    That will show:

    Changes to be committed:
      (use "git restore --staged ..." to unstage)
            renamed:    old-folder/file.txt -> new-folder/file.txt
    

    I tested with Git version 2.26.1.

    Extracted from GitHub Help Page.

提交回复
热议问题