git基础 学习git,首先要了解几个概念
working dir 这个是工作区,我们一般都处在工作区中
index 这个是缓存区,可以临时保存你的改动
HEAD 指向你最新提交的结果(上图没显示)
哈希号 可以认为是某次提交的身份证号码(上图没显示)
local repository : 本地仓库
remote repository:远程仓库
安装初始化git 正常我们都是在Linux下开发和使用git,如果在windows和苹果下开发,请自行百度
安装git
1 2 3 4 5 6 7 8 9 10 11 12 13 初始化git ssh-keygen git init git init [project-name] git clone [url] git config --list git config -e [--global] git config --global user.email "you@example.com" git config --global user.name "Your Name"
代码提交相关命令 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 git clone https://github.com/username/repo name.git git status . git add * git add -u [path] rm *&git rm * git rm -f * git rm --cached * git mv file_from file_to git log git commit git commit [file1] [file2] ... git commit -m 'message' git commit -a git commit --amend git commit -v git reset HEAD * git reset --mixed HEAD * git reset --soft HEAD * git reset --hard HEAD * git reset -- files git revert HEAD git revert HEAD~ git revert commit git checkout -- file git checkout branch|tag|commit -- file_name git checkout -- . git diff file git diff --stat git diff git diff --cached git diff HEAD git diff branch git diff branch1 branch2 git diff commit commit git log --grep=aplog git log git log --pretty=oneline git log --graph git log --abbrev-commit git log -num git log --stat git log --follow [file] git log -p [file] git log --oneline git stash git stash list git stash apply git stash drop git stash pop git stash apply stash@{0}
分支操作命令相关 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 git branch git branch -r git branch -a git branch -v git branch --merge git branch --no-merge git branch test git branch branch [branch|commit|tag] git branch --track branch remote-branch git branch -m old new git branch -d test git branch -D test git branch --set-upstream dev origin/dev git checkout test git checkout -b test git checkout -b test dev git merge test git merge --squash test git cherry-pick commit git cherry-pick -n commit git rebase master git rebase --onto master 169a6 git rebase --interactive git rebase --continue git rebase --skip git rebase --abort
远程分支相关命令 1 2 3 4 5 6 7 8 9 git fetch origin remotebranch[:localbranch] git merge origin/branch git pull origin remotebranch:localbranch git push origin branch git push origin localbranch:remotebranch git push origin :remotebranch git push origin remotebranch --delete git branch -dr branch git checkout -b [--track] test origin/dev
git远程源 git是一个分布式代码管理工具,所以可以支持多个仓库,在git里,服务器上的仓库在本地称之为remote。
个人开发时,多源用的可能不多,但多源其实非常有用。
正常的时候,我们在一个远程仓库作为本地代码仓库的源,但是有时候我们远程仓库的地址改变了,本地不管提交还是拉取代码都会出错,这时候就需要更新源。
1 2 3 4 5 6 git remote add origin1 git@github.com:weiqifa/demo.git git remote git remote -v git remote rename origin1 origin2 git remote rm origin git remote show origin
想清楚了再使用的命令 1 git push-f origin master
同步其他分支的某个文件 1 git show main:scripts/resource_tool>scripts/resource_tool
把main分支下的resource_tool 同步到当前分支下
打包项目源码命令相关 1 2 3 git clone –bare kernel/ * *git clone kernel.git/
打补丁命令相关 1 2 git diff ./ > *.patch patch -p1
查看历史分支图
学会查找资料 总结的命令不一定会都用到,但是学会如何查找资料解决自己的问题非常关键,很多时候我们提交可能提示出错,很多的时候都是分支跟master有冲突,或者从错误日志上可以看出问题,多动动脑子,很快就可以解决了。