git commit --amend -m ""
谬误提醒
error: failed to push some refs to 'https://github.com/xxx/xxx.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changes
**这是因为近程仓库曾经批改了,所以要先fetch,后pull
最初能力push**
提交近程仓库出错
src refspec master does not match any提交近程仓库出错,没有add,commit
git根本命令
Git global cofiggit config --global user.name "John Doegit config --global user.email johndoe@example.comGit initGit add/commit -mGit log:历史记录,最近到最远Git reset –-hard HEAD^ or HEAD~100//回退100Git reset –hard sha号有HEAD指针指向头Git reflog:记录每次命令Work tree stagereposityGit diff HEAD – 文件名 //查看work tree与repogit diff HEAD -- readme.txt工作区和版本库外面最新版本的区别Git checkout discard work tree的change Git checkout – 文件名Git reset既能够版本回退,也能够把暂存区的扭转撤销掉(unstage)在work tree删除文件,Git rm:从库中删除文件 ,之后要commit,才能够从库中删除 Git checkout – 文件名复原从repositorygit log --graph命令能够看到分支合并图。Git remote add origin(名字)git remote add origin https://github.com/xxx/learngit.gitgit push -u origin master //第一次git push origin mastergit clone近程库master指向最新的提交,再用HEAD指向mastergit checkout -b feature1 //建设分支并转换到分支Git branch 建设分支Git checkout 分支名字,转到分支git branch命令会列出所有分支,以后分支后面会标一个*号git merge dev合并到dev分支 --no-ff参数,示意禁用Fast forwardgit branch -d dev 删除分支git log --graph命令能够看到分支合并图。Git stash listgit stash pop,回到工作现场,discard stashgit remote –v //近程信息git push origin <branch-name>推送本人的批改;如果推送失败,则因为近程分支比你的本地更新,须要先用git pull试图合并;如果git pull提醒no tracking information,则阐明本地分支和近程分支的链接关系没有创立,用命令git branch --set-upstream-to <branch-name> origin/<branch-name>。git tag <tagname>用于新建一个标签git show <tagname>查看标签信息:git tag -a <tagname> -m "blablabla..."能够指定标签信息;git tag能够查看所有标签。git tag -d <tagname>能够删除一个本地标签;• 命令git push origin <tagname>能够推送一个本地标签;• 命令git push origin --tags能够推送全副未推送过的本地标签;git push origin :refs/tags/<tagname>能够删除一个近程标签。Git show HEADGit config –list –show-originGit diff work tree和stage的差异Git diff –staged.gitignore能够疏忽不必要的文件Blame:last modification on each line of fileGit push –u 出错,control panel/user/credential manager
git 删除commit
git rebase -i HEAD~
程序是反向的
git clone某分支
git branch -agit checkout -b bugfix-2.0x origin/bugfix-2.0.xgit pull origins//git remote show origingit checkout --track origin/serverfix //本地 serverfix追踪近程的 serverfix
git本地/近程分支名批改
git branch -r //列出近程分支git branch -a//列出所有,蕴含近程与本地git branch -v//verbosegit branch -m old_name new_namegit push origin --delete origin/old_name //删除近程分支 git push origin serverfix //本地 serverfix追踪近程的 serverfixgit pull -u origin new_name:newname new_name追踪近程newnamegit remote prune origin //近程曾经删除了,然而本人fetch的近程还在,应用prune
git 近程
git remote -v //verbosegit remote add pb https://github.com/paulboone/ticgit //增加近程git remote show origin //查看近程git remote remove origin//移除git remote rename pb paul//重名
git log
git log -p -2 //最初两个commitgit log --statgit log --pretty=onelinegit log --pretty=format:"%h -- %an--%ar--%s"git log since=2019.01.01 //自从2019.01.01到当初git log until=2019.01.01git log --since=2.weeks/2.months/2.yearsgit log -S function_name