工作常用的GIT操作记录

1. 拉取动作 git pull

git pull origin master 拉取远端主分支代码

强制拉取远端master代码

git fetch --all

git reset --hard origin/master

git pull

2. 本地创建分支

a) git checkout -b local_branch 创建本地分支local_branch 并切换到local_branch

b) git branch local_branch 创建本地分支local_branch但不会切换分支 +

git checkout local_branch 切换至local_branch

3. 查看分支 git branch

git branch 显示本地分支

git branch -r 显示远端分支

git branch -a 显示本地+远端分支

4. 查看本地修改状态 git status

git status

5. 将内容写入暂存区 git add

git add

6. 将暂存区内容添加到本地仓库 git commit

git commit

git commit --amend 给上次的commit打补丁

本地每个分支的commit记录是独立的,所以可以结合git stash和git commit完成本地不同分支的独立开发

7. 推送动作 git push

git push origin : -f(opt) 推送本地local_branch到远端remote_branch,-f指强制推送(可选项)

8. 保存未提交的修改 git stash

git stash 保存未提交的修改

git stash pop 推出最近一次stash动作的修改,会删除在list的记录

git stash list 显示stash的记录

git stash apply stash@{0} 应用指定的stash,不会删除list的记录

git stash drop stash@{0} 在list中删除指定的stash

9. 查看日志 git log

git log 显示所有日志

git log -n 显示最近的n次日志

10. 切换指定提交的分支 git checkout

git checkout

11. 回退动作 git reset

git reset HEAD~ 回退到上次提交

你可能感兴趣的:(Git,git)