0%
Good git resources
Git Move files from one repository to another while preserving git history
- mkdir merge_repo && cd merge_repo
- git clone --branch master --origin origin --progress -v git@github:xxx/projectA.git
- cd projectA
- git remote rm origin
- git filter-branch --subdirectory-filter subfolder/FOLDER_TO_KEEP -- --all
- git reset --hard && git gc --aggressive && git prune && git clean -fd
- (optional) mkdir anotherfolder && mv * anotherfolder && git add . && git commit
- cd ..
- git clone <git repository B url> projectB
- cd projectB
- git remote add repoA ../projectA
- git pull repoA master --allow-unrelated-histories
- git remote rm repoA
- git push
Git remote
Add new branch
- git checkout -b branch
- git switch -c branch
Add upstream remote
- git push -u origin master
- git branch --set-upstream-to origin/branch-name
- git push --set-upstream origin master
- git push origin --delete test
Git basic
- git clone --single-branch --branch
- git branch -a
- Delete remote branch: git push origin --delete [branchname]
- Delete local merged branch: git branch -d [branchname]
- Delete local unmerged branch: git branch -D [branchName]
- git log --graph --pretty=oneline --abbrev-commit
- git log --graph --decorate --oneline --simplify-by-decoration --all
- git log -L (where L is a number, for example git log -5)
- If can not add a folder by git
- git rm --cached folder
- git add folder
- Apply changes to another branch
- git stash
- git checkout anotherbranch
- git stash apply
Git advance
- git reset
- git rebase -i [previous commit]
- change a commit: git commit --amend
- git checkout -b test /test;
- git checkout -t /test
- git cherry-pick
- git stash push path/to/file git stash push path/to/file
Git config
- git config --global user.name “xx”
- git config --global user.email “xx@xx.com“
- git config --global core.editor “vim”
- Chinese mirror: github.com.cnpmjs.org
- npm install -g commitizen cz-conventional-changelog
echo ‘{ “path”: “cz-conventional-changelog” }’ > ~/.czrc
- git config --global core.autocrlf true
- sudo chown -R “${USER:-$(id -un)}” .