赞
踩
Git是一个分布式版本控制系统,广泛应用于软件开发项目中来追踪和控制代码的修改历史。
- # 设置全局用户名和邮箱
- git config --global user.name "Your Name"
- git config --global user.email "youremail@example.com"
- # 在当前目录创建一个新的Git仓库
- git init
- # 克隆远程仓库至本地
- git clone https://github.com/user/repo.git
- # 将某个文件添加到暂存区以准备提交
- git add <file_path>
- # 或者添加所有改动
- git add .
- # 提交暂存区的内容到本地仓库,附带提交信息
- git commit -m "Initial commit or describe your changes here"
- # 检查工作区和暂存区的状态
- git status
- # 获取远程仓库的最新改动并尝试自动合并到当前分支
- git pull origin <branch_name>
- # 将本地分支的更改推送到远程仓库的对应分支
- git push origin <branch_name>
- # 创建并立即切换到新的分支
- git checkout -b new_branch
- # 切换回已有分支
- git checkout <existing_branch>
- # 显示所有本地分支
- git branch
- # 显示所有本地和远程分支
- git branch -a
- # 合并指定分支到当前分支
- git merge other_branch
- # 暂存所有未提交的更改
- git stash
- # 恢复最近暂存的更改
- git stash pop
- # 显示提交历史记录
- git log
- # 将指定提交应用到当前分支
- git cherry-pick <commit_hash>
- git reset <file_path> # 将指定文件从暂存区移除,但保留工作区的更改
- git reset HEAD <file_path> # 类似于上述命令,取消暂存的同时恢复到HEAD版本
git checkout -- <file_path> # 抛弃工作区对指定文件的更改
- git rm <file_path>
- git commit -m "Remove file"
- git rm --cached <file_path>
- git commit -m "Remove file from repository"
- git mv <old_file_path> <new_file_path>
- git commit -m "Rename/move file"
- git diff # 查看尚未暂存的改动
- git diff --staged # 查看已暂存但未提交的改动
- git diff <commit1> <commit2> # 查看两个提交之间的差异
- # 回退到某一提交,并且丢弃之后的所有更改(谨慎操作)
- git reset --hard <commit_hash>
- git tag <tag_name> <commit_hash> # 标记特定提交
- git tag <tag_name> # 标记当前HEAD指向的提交
git push origin <tag_name>
- git tag -d <tag_name>
- git push origin :refs/tags/<tag_name> # 删除远程标签
git stash
git stash list
git stash apply <stash@{index}>
git stash pop
git submodule add <repository_url> <path_to_submodule>
git submodule update --remote
git add -p
- # 将feature分支的更改重新应用到master分支上,保持线性历史
- git checkout feature
- git rebase master
- git checkout master
- git merge feature
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。