Git 新建本地仓库:
git init
Git 下载远程代码:
git clone + url地址
Git 查看当前分支修改内容状态:
git status
Git 查看分支:
git branch -a
git branch
git branch -r
Git 重命名本地/远程分支:
git branch -m <old_branch> <new_branch>
1. 修改本地分支名
git branch -m <old_branch> <new_branch>
2. 删除要修改的远程分支名
git push origin --delete <old_branch>
3. 将改名后的分支push到远程
git push origin <new_branch>
Git 更新内容放入暂存区:
git add <filename>
git add .
Git 提交暂存区的内容:
git commit -m" the commit message "
git commit --amend
Git 拉取远程代码:
git pull origin <origin_branch>
git pull
Git 推送到远程代码:
git push origin <origin_branch>
Git 切换分支 / 创建并切换到本地新分支:
git checkout <branch_name>
git checkout -b <new_branch>
Git 放弃修改:
git checkout -- <filename>
git checkout .
Git 拉取远程分支到本地:
1. 拉取远程分支并更新本地分支(远程分支拉取到本地后 git branch 不会显示出来,所以需要进行 第二步 )
git pull
2.切换到远程拉取到本地的分支上
git checkout <branch_name>
git checkout -b <local_branch> origin/<origin_branch>
Git 删除本地分支:
git branch -d <branch_name>
git branch -D <branch_name>
Git 删除远程分支:
git push origin --delete <origin_branch>
git push origin :<origin_branch>
Git 查看日志(日志即分支的历史合并):
git log
git log --oneline
git log -[length]
git log --name-status
git log --author yourname
git log --skip=[skip]
git log -p
Git 撤销提交:
git reset --soft <commit id>
git revert HEAD
git reset --hard<commit id>
git revert commit
注意:reset 和 revert 的区别:revert 是用一次新的 commit 来回滚之前的 commit,reset 是直接删除指定的 commit