您的位置:首页 > 其它

GIT基本操作命令大全

2017-06-08 14:35 246 查看
1、更新文件
git pull

2、提交文件
git add *       ——提交所有修改的文件

git add [file1] [file2]

3、查看状态
git status

$ git status  
# On branch master  
# Changes not staged for commit:  
#   (use "git add <file>..." to update what will be committed)  
#   (use "git checkout -- <file>..." to discard changes in working directory)  
#  
#    modified:   readme.txt  
#  
no changes added to commit (use "git add" and/or "git commit -a")  

4、提交文件
git commit -m "代码提交信息"
5、查看日志
git log
通过第4步提交是提交到head上,还没有都远程仓库上。
6、提交到远程仓库
git push origin master

提交到master是有权限控制的,所以要使用git push origin HEAD:refs/for/master(把master可以换成任何你想提交的分支)将代码提交上去

7、将分支中的某次提交到master上
切换到master分支,git cherry-pick e6327f8d01276bcd22b38d53b1c7a907802a2c04(commit Id)

如果你现在的位置是在分支上,那么你需要切换master:git checkout master。切换前将你本次提交的id记下来,
然后使用命令,将分支上的这一次提交覆盖到master上:git cherry-pick e6327f8d01276bcd22b38d53b1c7a907802a2c04(commit Id)
然后使用git push origin HEAD:refs/for/master(把master可以换成任何你想提交的分支)

8、删除某次git add
一种是 git rm --cached "文件路径",不删除物理文件,仅将该文件从缓存中删除;一种是 git rm --f "文件路径",不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶)。
9、撤销某次提交git reset HEAD (撤销这个commit)

10、回到哪个版本git reset --hard commitid

11、放弃本地修改,直接覆盖之
git reset --hardgit pull

12、stash
通常遇到这个问题,你可以直接commit你的修改;但我这次不想这样。
看看git stash是如何做的。1、git stash
2、git pull
3、git stash pop接下来diff一下此文件看看自动合并的情况,并作出相应修改。
git stash: 备份当前的工作区的内容,从最近的一次提交中读取相关内容,让工作区保证和上次提交的内容一致。同时,将当前的工作区内容保存到Git栈中。
git stash pop: 从Git栈中读取最近一次保存的内容,恢复工作区的相关内容。由于可能存在多个Stash的内容,所以用栈来管理,pop会从最近的一个stash中读取内容并恢复。git stash list: 显示Git栈内的所有备份,可以利用这个列表来决定从那个地方恢复。git stash clear: 清空Git栈。此时使用gitg等图形化工具会发现,原来stash的哪些节点都消失了。13、撤回addgit reset file
14、解决文件名太长问题
git config --global core.longpaths true
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: