git常用命令的一些记录

git常用命令

1.通过git log查看提交信息
git branch -a查看全部分支,git branch查看分支
git checkout -b develop创建分支

2.通过git reset --soft <版本号>重置至指定版本的提交达到撤销提交的目的。git reset --soft aa990cff24534frg345greg435rh

3.通过git commit --amend修改提交信息:相当于会覆盖上次提交的错误信息,gitk图形界面上看不到上次提交的信息,git log也看不到之前的信息。而commit -m ''则是直接添加了一个提交信息。【只能修改commit后的信息,如果是push了的,则会引起merge,需要强制-f提交】

git commit --amend --no-edit:不做commit修改,只是合并提交。

4.解决冲突:
git rebase :多人在同一个分支上协作时,很容易出现冲突。即使没有冲突,后push的童鞋不得不先pull,在本地合并,然后才能push成功。[把分叉的提交历史“整理”成一条直线,看上去更直观。缺点是本地的分叉提交已经被修改过了]

git rebase --continue:用于修复冲突,提示开发者,一步一步地有没有解决冲突,fix conflicts and then run “git rebase --continue”
git rebase --abort会回到rebase操作之前的状态,之前的提交的不会丢弃;
git rebase --skip则会将引起冲突的commits丢弃掉;

pick f7f4f5f6 changed my name a bit
edit 34535e updated README formatting and added blame
pick a5f4g4h3 added cat-file


忘记pull后
git commit
然后操作pull 报错error: There was a problem with the editor ‘vi’.
Not committing merge; use ‘git commit’ to complete the merge.
然后想要撤回操作 git reset --soft origin/develop 撤销不了提示 fatal: Cannot do a soft reset in the middle of a merge.
执行 git commit --amend --no-edit 后提示fatal: You are in the middle of a merge – cannot amend.
可以先执行 git reset --merge
然后git rebase
git rebase --continue
查看 处理冲突
git diff -w 查看冲突文件
这样操作后,再执行 git reset --soft origin/develop 撤销提交,再做相关操作。。

5.使用如下命令添加远程仓库:git remote add origin git@github.com:segwgehwh

6.合并分支merge branch "develop" into master

7.版本控制系統的branch功能也很有意思,若同时修改bug,又要加入新功能,可以fork出一个branch:一个专门修bug,一个专门加入新功能,等到稳定后再merge合并
git branch bug_fix 建立branch,名为bug_fix
git checkout bug_fix 切换到bug_fix
git checkout master 切换到主要的repo
git merge bug_fix 把bug_fix这个branch和现在的branch合并

8.若有remote的branch,想要查看并checkout
git branch -r 查看远程branch
git checkout -b bug_fix_local bug_fix_remote 把本地端切换为远程的bug_fix_remote branch并命名为bug_fix_local

9.查看repo状态
git log 可以查看每次commit的改变
git diff 可以查看最近一次改变的內容,加上参数可以看其它的改变并互相比较
git show 可以看某次的变更

10.删除错误提交的commit方法:
git reset --hard <commit_id>
git push origin HEAD --force 强制本地覆盖远程

11.git cherry-pick <commit-id>:用于拷贝某个单独的patch,它的灵活性更大,而rebase主要用于整个分支的一次性合并。

12.用git status查看状态

coommit 的一些描述规范

feat:新功能(feature)
fix:修补bug
chore:构建过程或者辅助工具变动
test:增加测试
docs:文档(documentation)
style:格式/样式(不影响代码运行的变动)
refactor:重构(既不是新增功能也不是修改bug)

问题

1.问题:On branch develop Your branch is up to date with 'origin/develop'

Changes not staged for commit:
modified: test.txt

no changes added to commit

解决:提交有空文件夹,可先add试试

2.问题:error: src refspec develop does not match any. error: failed to push some refs
解决:分支没创建

3.To github.com:michaelliao/learngit.git ! [rejected]master -> master (fetch first)error: failed to push some refs to 'git@github.com:michaelliao/learngit.git'hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again.[这说明有人先于我们推送了远程分支]
解决:git pull --rebase origin master
git push -u origin master

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值