git常用命令
1.从本地secondtask推送到test2
git push origin secondtask(本地:test2(:前面没空格,有空格的话会删除远程分支并新建一个和本地分支名字相同的远程分支)
2.暂存刚新加的文件
git stash -k -u
3.删除暂存区的记录
git stash drop
4.查看本地和远程的对应关系
git branch -vv
5.第一次提交分支的时候与远程分支建立联系
git push -u origin my_branch
git branch --set-upstream my_branch origin/my_branch
git push --set-upstream origin/master
6.从远程分支创建并切换到新分支
git checkout -b 本地分支名x origin/远程分支名x
git fetch origin 远程分支名x:本地分支名x 不会自动切换
7.从本地a或者远程a分支检出 指定文件到当前分支
git checkout a(origin a) -- 文件名
8.rm -f ./.git/index.lock 解决如下问题:
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
9.git stash drop 误删解决
* git fsck --lost-found 查看最近删除记录
* git show e2c07caec2b995ba75ce1abd15796c6f1686d532 展示是否是你修改的代码
* git merge e2c07caec2b995ba75ce1abd15796c6f1686d532 合并恢复(直接提交到本地了)
10.删除远程分支
git push origin :old-local-branch-name
git push origin -d BranchName
git push origin --delete BranchName
11.重命名本地分支
git branch -m oldname newname
12.查看git stash内容
git show -p stash@{0}
13.git stash 坑
做修改后先git stash ,然后git pull origin master ,然后git stash pop ,如果出现冲突,stash里面的内容还原回来了,暂存区也还有一份。
14.重命名本地分支
git branch -m oldname newname
15.本地找不到远程分支
git fetch同步一下
16.本地项目推送到远程分支
git remote add origin https://github.com/XuDaojie/Lee.git(远程仓库地址)
git push -u origin master -- 将本地仓库push远程仓库,并将origin设为默认远程仓库
17.git给log设置别名来快速查看友好的log信息
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset - %C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
18.删除远程分支后git branch -a 还能看到的问题(显示的是本地仓库的)
git remote show origin 来查看有关于origin的一些信息,包括分支是否tracking。
git remote prune origin