git
用户信息及初始化
设置用户信息
git config --global user.name
git config --global user.email
初始化
git init --bare
git remote add origin git@120.25.77.143:some-repo.git
强制拉取
git fetch --all
git reset --hard origin/master
移出版本控制
-n:执行命令时,不会删除任何文件,而是展示此命令要删除的文件列表预览
git rm -r -n --cached "bin/"
最终执行命令
git rm -r --cached "bin/"
.gitignore 示例
node_modules/
查看 commit
显示最近的两次提交记录
git log -p -2
列出提交者各自提交次数
git log --pretty='%aN' | sort | uniq -c | sort -k1 -n -r
查看提交记录 source git log --pretty=short git log --pretty=format:'%h was %an, %ar, message: %s'
远程仓库 source
删除远程仓库 git remote rm [name]
查看远程仓库
git remote -v
添加远程仓库
git remote add [name] [url]
修改远程仓库
git remote set-url --push[name][newUrl]
分支(branch)操作
查看分支
git branch // 查看本地分支
git branch -a // 查看所有分支(本地和远程)
git branch -r // 查看远程分支
创建本地分支(注意新分支创建后不会自动切换为当前分支)
git branch [name]
切换分支
git checkout [name]
git checkout -b [name] // 创建新分支并立即切换到新分支
删除分支
- -d 选项只能删除已经参与了合并的分支,对于未有合并的分支是无法删除的
- -D 如果想强制删除一个分支,可以使用-D 选项
git branch -d [name]
git push origin --delete <branchName> // 删除远程分支?
删除所有本地 tag
git tag -d $(git tag -l)
https://stackoverflow.com/questions/44702757/how-to-remove-all-git-origin-and-local-tags/44702758
合并分支(将名称为[name]的分支与当前分支合并)
git merge [name]
撤销修改
Various ways to remove local Git changes
git checkout . // Removes Unstaged Tracked files ONLY [Type
git clean -f // Removes Unstaged UnTracked files ONLY [Type
git reset --hard // Removes Staged Tracked and UnStaged Tracked files ONLY[Type 1, Type 2]
git stash -u // Removes all changes [Type 1, Type 2, Type
tag
2.6 Git 基础 - 打标签 打标签
git tag v0.1
git push --tags
列出远程的标签
https://stackoverflow.com/questions/25984310/how-to-see-remote-tags
git ls-remote --tags
查看标签
git tag
删除标签
git tag -d <tagname>
git push origin --delete tag <tagname>
git hooks
post-receive 权限
chmod +x hooks/post-receive
相关
gitignore
这三种写法是有区别的
bin 忽略所有名称为 bin 的文件和文件夹
bin/ 忽略所有名称为 bin 的文件夹
/bin/ 忽略所有在根目录下的名称为 bin 的文件夹
git 删除名称和 tag 一样的分支
git push origin :refs/heads/v3
重置 last commit
git reset --soft HEAD~1
强制拉取两个没有共同父节点的分支
git pull origin gitlab-pages --allow-unrelated-histories
跳过 commit hook
git commit -m 'msg' --no-verify
rebase
git rebase -i HEAD~n
p <commit>
s <commit>
comment
修改最后一次 commit 的 comment
git commit --amend
推送所有
git push --all
git push <remote> --tags
merge tag
git fetch --tags origin
git merge <tag>
比对两个文件
git diff --no-index file_a file_b
git submodule
git submodule update --init --recursive
https://www.vogella.com/tutorials/GitSubmodules/article.html
删除 gitsubmodule
To remove a submodule you need to:
- Delete the relevant section from the .gitmodules file.
- Stage the .gitmodules changes git add .gitmodules
- Delete the relevant section from .git/config.
- Run git rm --cached path_to_submodule (no trailing slash).
- Run rm -rf .git/modules/path_to_submodule (no trailing slash).
- Commit git commit -m "Removed submodule "
- Delete the now untracked submodule files rm -rf path_to_submodule
合并两个 git 仓库
Moving One Git Repository Into Another As A Subdirectory > How to move all files in current folder to subfolder?
cd /home/machete/old-project
mkdir old-project
shopt -s extglob
mv !(old-project) old-project
git commit -a -m "Preparing old project for move"
或者用 git pull 也行
cd /home/machete/new-project
git remote add temp /home/machete/old-project
git fetch temp
git merge temp/master --allow-unrelated-histories
git remote rm temp