Git常用命令
个人在开发时,习惯使用GitDesktop来完成版本控制、合并与团队开发等任务,但
某些情况下GitDesktop用不了,因此记录一些常用的Git命令
1.基本命令
- 初始化仓库
git init - 克隆仓库
git clone <repository_url> - 查看当前状态
git status - 添加文件到暂存区
git add <file> - 添加所有更改的文件:
git add. - 提交更改
git commit -m "commit message"
2.分支管理
- 查看所有分支
git branch - 创建新分支
git branch <branch_name> - 切换分支
git checkout <branch_name> - 合并分支
git merge <branch_name> - 删除分支
git branch -d <branch_name>
3.远程仓库
- 查看远程仓库
git remote -v - 添加远程仓库
git remote add <remote_name> <repository_url> - 推送更改到远程仓库
git push <remote_name> <branch_name> - 从远程仓库拉取更改
git pull <remote_name> <branch_name> - 获取远程更新
git fetch <remote_name>
4.其他
- 撤销未提交的更改
git checkout -- <file> - 查看文件的差异
git diff - 多分支提交(从一个分支中选择特定的提交)
git checkout target-branch
git cherry-pick commit-hash - 回退版本
git reset --hard HEAD^# 回退到上个版本
git reset --hard HEAD~3# 回退到前 3 次提交之前,以此类推,回退到 n 次提交之前
git reset --hard commit-hash# 退到/进到 指定 commit-hash - 拉取远程分支到本地新分支
git checkout -b local_branch_name origin/remote_branch_name

Comments NOTHING