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

5.使用如下命令添加远程仓库:git remote add origin [email protected]: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 '[email protected]: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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章