Git 命令总结

git pull 出错 fatal: Could not read from remote repository.Please make sure you have the correct access rights.and the repository exists.
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

出现这个问题是因为,没有在github账号添加SSH key

1,通过ssh-keygen命令在自己的电脑上生成公钥和私钥;
ssh-keygen -t rsa -C [email protected]
2,进入.ssh文件夹,然后打开id_rsa.pub:
将内容交给你们的git服务器管理员。
然后当他配置好之后就可以访问了。
3,然后就可以使用git clone将远程仓库克隆下来了。
git clone [email protected]/ihotel_qa.git
git本地用户名和密码配置:
$ git config --global user.name "wirelessqa" $ git config --global user.email [email protected]
4,查看远程仓库版本:
ebj1412:ihotel_qa user$ git remote -v origin [email protected]:qa_department/ihotel_qa.git (fetch) origin [email protected]:qa_department/ihotel_qa.git (push)
5,查看远程分支
使用git remote show origin
*remote origin Fetch URL: [email protected]:qa_department/ihotel_qa.git Push URL: [email protected]:qa_department/ihotel_qa.git HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date)
6,拉取远程分支
再使用git checkout -b xxx_xxx remotes/origin/xxx_xxx
7,在远程服务器上创建分支
使用git push -u origin xxx_xxx将本地分支推到服务器
8,删除远程服务器上的分支
如果要删除服务器上的分支git push origin :xxx_xxx
9,查看所有分支
git branch -all
10,多人合作操作解决冲突:
https://segmentfault.com/a/1190000009642318
http://blog.csdn.net/l799069596/article/details/47126503
11,git的常用命令:
http://blog.csdn.net/dengsilinming/article/details/8000622
12,一种是 git rm --cached "文件路径",不删除物理文件,仅将该文件从缓存中删除;
一种是 git rm --f "文件路径",不仅将该文件从缓存中删除,还会将物理文件删除(不会回收到垃圾桶)
假如你有文件不小心commit到了服务器那么你想要删除它,可以使用:git rm -- cached "路径+文件名" , 用-r参数删除目录
git rm -r --cached dirname git commit -m 'say something' git push origin master
一、windows提交到gitHub远程仓库时,错误日志记录:

echo "# hibernateEntity" >> README.md
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/jd2017/hibernateEntity.git
git push -u origin master

D:\JindeWorkspaces\hibernateEntity [master +6 ~0 -0 !]> git remote add origin ht
tps://github.com/jd2017/hibernateEntity.git
fatal: remote origin already exists.
D:\JindeWorkspaces\hibernateEntity [master +6 ~0 -0 !]> git remote rm origin
error: Could not remove config section 'remote.origin'
D:\JindeWorkspaces\hibernateEntity [master +6 ~0 -0 !]> git remote add origin ht
tps://github.com/jd2017/hibernateEntity.git
fatal: remote origin already exists.
D:\JindeWorkspaces\hibernateEntity [master +6 ~0 -0 !]> git remote add origin ht
tps://github.com/jd2017/hibernateEntity.git
D:\JindeWorkspaces\hibernateEntity [master +6 ~0 -0 !]> git push -u origin maste
r
Counting objects: 3, done.
Writing objects: 100% (3/3), 207 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://github.com/jd2017/hibernateEntity.git

  • [new branch] master -> master
    Branch master set up to track remote branch master from origin.

提示出错信息:fatal: remote origin already exists.

解决办法如下:

1、先输入$ git remote rm origin
2、再输入$ git remote add origin [email protected]:djqiang/gitdemo.git 就不会报错了!
3、如果输入$ git remote rm origin 还是报错的话,error: Could not remove config section 'remote.origin'. 我们需要修改gitconfig文件的内容
4、找到你的github的安装路径,我的是
C:\Users\Admin\AppData\Local\GitHub\PortableGit_6d98349f44ba975cf6c762a720f8259a267ea445\etc
5、找到一个名为gitconfig的文件,打开它把里面的[remote "origin"]那一行删掉就好了!

…or create a new repository on the command line
echo "# autofun" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/jd2017/autofun.git git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/jd2017/autofun.git git push -u origin master
…or import code from another repository
You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
git 常用命令:
建分支:git branch test
切换分支:git checkout test
查看分支:git branch
删除分支: git branch -d test

error: src refspec master does not match any.
引起该错误的原因是,git提交空目录上去造成的,添加文件后提交解决;

1. 未使用git add 缓存代码

  • 使用git checkout -- filename,注意中间有--
    git checkout -- filename
  • 放弃所有文件修改 git checkout .
    git checkout .
  • 此命令用来放弃掉所有还没有加入到缓存区(就是 git add 命令)的修改:内容修改与整个文件删除
  • 此命令不会删除新建的文件,因为新建的文件还没加入git管理系统中,所以对git来说是未知,只需手动删除即可

2. 已使用git add 缓存代码,未使用git commit

  • 使用 git reset HEAD filename
    git reset HEAD filename
  • 放弃所有文件修改 git reset HEAD
    git reset HEAD
  • 此命令用来清除 git 对于文件修改的缓存。相当于撤销 git add 命令所在的工作。在使用本命令后,本地的修改并不会消失,而是回到了第一步1. 未使用git add 缓存代码,继续使用用git checkout -- filename,就可以放弃本地修改

3. 已经用 git commit 提交了代码

  • 使用 git reset --hard HEAD^ 来回退到上一次commit的状态
    git reset --hard HEAD^
  • 或者回退到任意版本git reset --hard commit id ,使用git log命令查看git提交历史和commit id
    git reset --hard commit id

markdown 用法
参考日志

你可能感兴趣的:(Git 命令总结)