git基本命令
git提交代码: 修改---->add 提交到暂存区---->commit 提交到本地仓库------>push 推到远程仓库
[root@localhost git]# git add . #将当前目录下修改的东西都提交,没指定文件
[root@localhost git]# git add bash #添加bash文件
[root@localhost git]# git commit -m "bash" # -m 表示提交的注释
[slave 27b1758] bash
1 file changed, 1 insertion(+)
create mode 100644 bash[root@localhost git]# git remote add monmon 192.168.25.133:/root/git #
[root@localhost git]# git push monmon
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 287 bytes | 0 bytes/s, done.
Total 2 (delta 0), reused 0 (delta 0)
To 192.168.25.133:/root/git
2b19488..27b1758 slave -> slave
分支:
查看当前所属分支 : git branch
查看远程仓库所有分支: git branch -a
查看本地仓库所有分支:git branch -v
切换到bbb分支: git checkout bbb
创建aaa分支: git branch aaa
拷贝当前所在分支到新分支,然后推送:git checkout -b 新分支名称 然后 git push origin 新分支名称
将当前分支跟指定分支合并: git merge 指定分支名
[root@localhost git]# git branch -d test #-d 删除分支
Deleted branch test (was 6b6c8fa).[root@localhost git]# git branch -r #查看远程分支与本地分支的链接
master/master
master/slave[root@localhost ~]# git clone 192.168.25.133:/root/git/slave #默认clone的是master分支
[root@localhost ~]# git clone -b slave 192.168.25.133:/root/git/slave #指定克隆slave分支
[root@localhost git]# git push 192.168.25.133:/data/git/ fenzhong1:fenzhong1 #推送本地分支到远程分支
Total 0 (delta 0), reused 0 (delta 0)
To 192.168.25.133:/data/git/
* [new branch] fenzhong1 -> fenzhong1
删除代码:
一般情况下,你通常直接在文件管理器中把没用的文件删了,或者用
rm命令删了:$ rm test.txt这个时候,Git知道你删除了文件,因此,工作区和版本库就不一致了,
git status命令会立刻告诉你哪些文件被删除了:[root@localhost git]# git status deleted: test.txt现在你有两个选择,一是确实要从版本库中删除该文件,那就用命令
git rm删掉,并且git commit:$ git rm test.txt rm 'test.txt' $ git commit -m "remove test.txt" [master d46f35e] remove test.txt 1 file changed, 1 deletion(-) delete mode 100644 test.txt现在,文件就从版本库中被删除了。
另一种情况是删错了,因为版本库里还有呢,所以可以很轻松地把误删的文件恢复到最新版本:
[root@localhost git]# git status
# deleted: slave[root@localhost git]# git checkout -- slave
git checkout其实是用版本库里的版本替换工作区的版本,无论工作区是修改还是删除,都可以“一键还原”
git push 出现warning:
[root@localhost gut]# git push test
warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:git config --global push.default matching
To squelch this message and adopt the new behavior now, use:
git config --global push.default simple
解决方法:
[root@localhost gut]# git config --global push.default matching
git push第一次报错:
原因:
本地没有update到最新版本的项目(git上有README.md文件没下载下来)
本地直接push所以会出错。
解决方法:
git pull --rebase origin master
git diff 代码比对

浙公网安备 33010602011771号