Git: How do I move the contents of a gh-pages branch to a docs / history-saving directory?

So github recently implemented a function to use a docs/directory masterinsteadgh-pages . And it is useful for some use cases like mine.

The script is a git repo with a branch masterand gh-pages(the "old" way to make github pages), and I want to move everything in the branch gh-pagesto docs/in a directory master(the "new" way to create github pages).

I know what I can use git checkout master; git checkout gh-pages -- docs, but this will delete the history from the files gh-pages, which is undesirable.

I searched with git subtreeand git filter-branchwithout success.

So the question is: is there a magic one-line gitcommand to move the contents of another branch to a subdirectory while saving the story?

+4
source share
3 answers

git subtreesPerfect for this. You mentioned that you "played" with them, but you tried:

git subtree add --prefix=docs origin gh-pages

Check out docs-subtreebranch

+1
source

I don't know if there is a single line command, but you can try rebase and then combine it into master:

git checkout gh-pages
git rebase master
git checkout master
git merge --no-ff gh-pages
0
source

, git merge ( @Wikiti , ), , .

, , git reset .

This is not perfect, and I recommend that any git specialists or gitlab staff offer the best solutions. In the hope that this will help others who are trying to move away from the branch gh-pages, this is how I did it:

git checkout master
git checkout -b master-docs
git merge gh-pages

# Reset the "master" files so that files deleted are left untouched by the merge
git reset src/
git checkout src/
git reset any-other-master-files
git checkout any-other-master-files

# Manually edit any conflicts, e.g. in .gitignore (with your favourite editor)
vi .gitignore
git add .gitignore
vi any-other-conflicting-files
git add any-other-conflicting-files

# Move the "gh-pages" files into "docs/" directory
mkdir docs
git mv *.md docs/
git mv *.html docs/
git mv _posts docs/
git mv _layout docs/
git mv any-other-gh-pages-files docs/

# Check that everything looks OK, there should be only files added to docs/
# If not, go through last steps again
git status

# Confirm the merge
git commit

# Push to origin
git push -u master-docs

# Go to github, make a pull req from master-docs to master for peer review

(The result does not look bad )

0
source

Source: https://habr.com/ru/post/1651644/


All Articles