Git常用命令

-- origin远程仓库名,master分支名,-f为force,意为:强行、强制。
git push -f origin master

-- 远程新建分支,本地没有该分支,会自动跟踪远程的同名分支
git checkout --track origin/branch_name
 
-- 已有本地分支创建关联
git branch --set-upstream-to  origin/branch_name  local_branch_name 

-- 取消本地分支与远端分支的关联
git branch --unset-upstream  local_branch_name 

-- 更新本地分支列表与远程一致
git remote update origin --prune

-- 撤销本地commit 
git reset head~

-- 查看当前状态
git status

-- 查看提交记录
git log

-- 查看所有分支
git branch -a 

-- 删除分支
git branch -d branch_name

-- 切换分支
git checkout branch_name

-- 合并分支
git merge branch_name

-- 仅修改 message 信息
git commit --amend --message="modify message by daodaotest"

-- .gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
-- 解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
posted @ 2022-02-15 18:06  shenghuotaiai  阅读(20)  评论(0编辑  收藏  举报