CodeStandard/git.txt
2024-06-07 20:00:25 +03:00

54 lines
1.9 KiB
Plaintext

0. Add new repository to Ubuntu server
cd /var/repos
mkdir Name.git
cd Name.git
git init --bare
cd ..
sudo chown -R git Name.git
sudo chmod -R a+rwx /var/repos
1. Move a bunch of files through git mv
for FILE in src/*.h; do git mv $FILE include/; done
2. Submodules
https://git-scm.com/docs/git-submodule
git submodule update --init --recursive --remote
git config submodule.moduleName.url git@repo:/var/repos/common/CodeStandard.git
3. Remove submodule
https://gist.github.com/myusuf3/7f645819ded92bda6677
4. Move files with history into another repo
https://medium.com/@ayushya/move-directory-from-one-repository-to-another-preserving-git-history-d210fa049d4b
5. Change origin
git remote rm origin
git remote add origin git@repo:/var/repos/CodeStandard.git
git config master.remote origin
git config master.merge refs/heads/master
6. Push commits to remote (origin)
git push -u origin master
7. move files with history
https://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
git filter-branch --subdirectory-filter <directory 1> -- --all
git pull repo-A-branch master --allow-unrelated-histories
8. Remove history for inactive files = delete all and restore active
https://stackoverflow.com/questions/17901588/new-repo-with-copied-history-of-only-currently-tracked-files
$ git checkout master
$ git ls-files > keep-these.txt
$ git filter-branch --force --index-filter \
"git rm --ignore-unmatch --cached -qr . ; \
cat $PWD/keep-these.txt | tr '\n' '\0' | xargs -d '\0' git reset -q \$GIT_COMMIT --" \
--prune-empty --tag-name-filter cat -- --all
$ rm -rf .git/refs/original/
$ git reflog expire --expire=now --all
$ git gc --prune=now
9. Remove file from history
https://myopswork.com/how-remove-files-completely-from-git-repository-history-47ed3e0c4c35
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD