We also wanted to remove that folder from the source repository. Because git command line instructions can be really cryptic, and because there is one or two tricks to know, we are sharing our experience to complete the process. In the beginning we have a repository holding the source code of a web platform and the source code of the related presentational website.
As time goes by, we understood that having both projects in the same repository was far from being an ideal situation:. It became obvious to us that the website part should live in its own project.
The ascii image below shows the initial situation. We had to move the website folder to its own git repository. The requirements were to keep the website folder history in the destination-repository and completely get rid of this folder in the source-repository. In this post, we cover the first requirement: move the folder with history from one repository to another. To avoid a too long article, we will cover the second requirement removing the folder with history from the source repository in a future post.
To avoid committing our changes to the source repository, let's cut the link between the local repository and its origin:. November 10, Here are a few ways our teams use GitHub Discussions internally to build community, simplify workflows, and get key insights into our work.
November 9, This latest release sees the introduction of a new role, a new webhook for GitHub Actions, and a bright edge to dark mode. Back to GitHub. So, in your case, don't work so hard: Ref: Git mv docs. From the git mv man page :. In the second form, the last argument has to be an existing directory; the given sources will be moved into this directory. The index is updated after successful completion, but the change must still be committed.
See commit c57f by Matthieu Moy moy for Git 1. Git used to trim the trailing slash, and make the command equivalent to ' git mv file no-such-dir ', which created the file no-such-dir while the trailing slash explicitly stated that it could only be a directory. This patch skips the trailing slash removal for the destination path.
The path with its trailing slash is passed to rename 2 , which errors out with the appropriate message:. Error "bad source I think my messege will be deleted But I just want to warn "lurscher" and others who got the same error: be carefull doing. At least my project is not lost. Now I have my project in newFolderName, but without the history. Just want to warn, be carefull using advice of "Andres Jaan Tack", if you dont want to lose your git hsitory. I had a similar problem with git mv where I wanted to move the contents of one folder into an existing folder, and ended up with this "simple" script:.
The reason for doing this is that git seems to have problems moving files into existing folders, and it will also fail if you try to move a file into a non-existing folder hence mkdir -p. The nice thing about this approach is that it only touches files that are already checked in to git.
By simply using git mv to move an entire folder, and the folder contains unstaged changes, git will not know what to do. After moving the files you might want to clean the repository to remove any remaining unstaged changes - just remember to dry-run first!
You can move your files using your favorite tools command line, graphical file explorer and git will figure out that you made move instead of deletion and creation once you staged your operations , as suggested by Andres but if you make too many modifications, as Erik Kaplun pointed out, explicit git mv could help. Some GUI git tools like GitHub Desktop does not provide direct access to stage: you can select and deselect modifications, but it does not modify the underlying git stage.
You need to use a more powerful git tool, like the command-line tool or the authentic git GUI to stage the changes, then GitHub Desktop too will show the operation as rename.
I had similar problem, but in folder which I wanted to move I had files which I was not tracking. You can use this script. The advantage of this solution over other solutions is that it moves folders and files recursively and even creates the folder structure if it doesn't exist.
If you are using GitLab , its integrated Web-IDE, can be used for some file management tasks including move and rename without local clone. The changes will be shown in the web-ide.
Right drag source to destination select source, hold the right mouse key, drag to destination, release mouse. A menu will be displayed which has Git Move versioned items and Git Move and rename versioned items. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
0コメント