git的使用

发布时间:2014-04-30 23:04:32 阅读:1593次

composer config -g -l

[root@web_test zmSuper]# cat /root/.composer/auth.json 
{
    "bitbucket-oauth": {},
    "github-oauth": {},
    "gitlab-oauth": {},
    "gitlab-token": {},
    "http-basic": {
        "code.zm.shzhanmeng.com": {
            "username": "wangbo",
            "password": "214wnj21ljy"
        }}
}

https://blog.csdn.net/weixin_33868027/article/details/91899729

git 永久记住密码

git config --global credential.helper store

git端口号
cd ~
vim .ssh/config
添加
Host code.test.com
port 10022

[root@lnmp laravel5.6]# git branch --set-upstream yansiyu origin/yansiyu

进入隐藏文件夹

cd .git

vim config

尽量用dos命令而不要用mingw64

http://blog.csdn.net/whu_zhangmin/article/details/18596665/

使用命令checkout来恢复:git checkout -- file_name

如果要恢复多个被删除的文件,可以使用批处理命令:

git ls-files -d | xargs git checkout --

如果要恢复被修改的文件,命令:git ls-files -m | xargs git checkout --

git rm 和 rm

http://m.blog.csdn.net/article/details?id=49668863

http://blog.csdn.net/xiaoyuanzhiying/article/details/44085135

http://blog.csdn.net/jfkidear/article/details/12152167

$ git add -u

$ git commit -m "delete test"

$ git push

免认证http://jingyan.baidu.com/article/6d704a13171c7428db51cacd.html

   ssh-keygen -t rsa -C "test115@github.com"

   ssh-keygen -t rsa -C "git@github.com"
   cd .ssh/

将id_ras.pub的内容复制到github中的ssh配置中

打开浏览器登陆github,在自己的账户面板下找到
SSH keys这一栏,打开后即会看到目前该账户下已进行过SSH认证的机器,
选择Add SSH key之后,将前一步复制的内容粘贴至Key中,同时需要编辑一个Title来说明此Key认证的是哪一台机器,通常会使用计算机的名字。

 1307  ssh git@github.com
 1308  ssh -T git@github.com

键入 ssh git@github.com进行连接认证,

http://blog.csdn.net/yuquan0821/article/details/8210944

在github.com上 建立了一个小项目,可是在每次push  的时候,都要输入用户名和密码,很是麻烦

原因是使用了https方式 push

在termail里边 输入  git remote -v 

可以看到形如一下的返回结果

origin https://github.com/test115/mygit.git (fetch)

origin https://github.com/test115/mygit.git (push)

下面把它换成ssh方式的。
1. git remote rm origin
2. git remote add origin git@github.com:test115/mygit.git
3. git push origin

首先在服务器上新建mygit版本库

https://github.com/test115/mygit

在自己的机器上执行:

输入用户名密码:test115

1399  mkdir test
1400  cd test
1401  ls
1402  touch README.md
1403  git init
1404  git add README.md
1405  git commit -m 'first commit'
1406  git remote add origin https://github.com/test115/mygit.git
1407  git push origin master
1410  touch 1.php
1411  vim 1.php
1412  git add 1.php
1413  git commit -m 'test'
1414  git remote add origin https://github.com/test115/mygit.git
1415  git push origin master
在服务器上vim 1.php修改下内容
1420  git pull
1421  ls
1422  vim 1.php
1423  git -help
1424  git --help
1425  git pull origin master
1426  ls
1427  cat 1.php

1.php

2.php

将服务器的修改同步到本地

http://blog.csdn.net/iaiti/article/details/39557951

GitHub问题之恢复本地被删除的文件

git checkout 文件夹名

转:http://blog.csdn.net/manageer/article/details/8834314

Git 使用教程

1:下载Git Git for Windows

2:点击安装,依次默认下一步

3:安装完成

4:设置SSH建立计算机与Github的链接

4.1 点击开始菜单找到Git Bash,并点击:

4.2 运行命令 cd ~/.ssh 检查自己的电脑上是否存在ssh keys

如果显示No such file or directory 则需要去创建一个新的ssh keys

4.3 创建新的ssh keys

运行命令:$ ssh-keygen -t rsa -C "your_email@youremail.com"点击回车

点击回车

输入你的passphrase(密码),并重新输入确认

注:在Enter passphrase 的时候,输入的密码是看不到的,其实已经输入了,输完后点击回车就可以了

这样一个新的keys就创建完成了,上面代码显示,密匙位置放在了C:/Users/用户名/.ssh/文件夹中。(.ssh文件夹可能是隐藏的,需要查看隐藏文件

4.4 将你新生成的ssh keys 添加到github中

在 GitHub 网站点击“Account Settings” > 点击 “SSH Public Keys”> 点击 “Add another public key”

在本机找到你创建的密匙文件id_rsa.pub,使用记事本打开,复制里面所有的内容,粘贴到网站key的文本框中,点击Add Key 保存

5:测试一下我们的设置是否正确

输入命令:$ ssh -T git@github.com

输入yes

我本机显示连接关闭,然后我继续执行上诉命令,提示输入passphrase(密码),输入前面自己设置的passphrase。回车登录成功

6:在本地设置Git信息

6.1设置用户名和邮箱

$ git config --global user.name"Firstname Lastname"

$ git config --global user.email"your_email@youremail.com"

此处用户名为自己的实际姓名(自定义的),而非登录用户名

Git 创建一个库Create a Repository

官网注册

https://github.com

1:点击 New repository

2:输入库的相关信息,然后点击Create Repository

3:上传一个文件

3.1首先在本地创建一个目录(这个目录名需要和上一步创建的项目名相同):依次执行下列命令行

在自己的机器上执行如下
mkdir Helloworld
cd Helloworld
git init
touch README
git add README git commit -m 'first commit'

3.2:打开本机的c:/User/用户名/Helloworld文件夹中的readme文件(使用记事本)编辑内容,保存。

3.3:将文件提交到github中的库中,执行下列命令行

git remote add origin git@github.com:github用户名/Helloworld.git
git push -u origin master 

4:这样我们就已经把一个文件上传到了githb代码库中了!

问题:

当要push代码到git时,出现提示:

error:failed to push some refs to ...

Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:

  1. $ git push origin master
  2. To ../remote/
  3. ! [rejected]        master -> master (non-fast forward)
  4. error: failed to push some refs to '../remote/'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again.  See the 'non-fast forward'
section of 'git push --help' for details.
This error can be a bit overwhelming at first, do not fear. Simply put, git cannot make the change on the remote without losing commits, so it refuses the push. Usually this is caused by another user pushing to the same branch. You can remedy this by fetching and merging the remote branch, or using pull to perform both at once.
In other cases this error is a result of destructive changes made locally by using commands like git commit --amend or git rebase. While you can override the remote by adding --force to the push command, you should only do so if you are absolutely certain this is what you want to do. Force-pushes can cause issues for other users that have fetched the remote branch, and is considered bad practice. When in doubt, don’t force-push.

问题(Non-fast-forward)的出现原因在于:git仓库中已经有一部分代码,所以它不允许你直接把你的代码覆盖上去。于是你有2个选择方式:

1,强推,即利用强覆盖方式用你本地的代码替代git仓库内的内容

git push -f

2,先把git的东西fetch到你本地然后merge后再push

$ git fetch

$ git merge

这2句命令等价于
  1. $ git pull

可是,这时候又出现了如下的问题:

上面出现的 [branch "master"]是需要明确(.git/config)如下的内容
[branch "master"]
remote = origin

merge = refs/heads/master

这等于告诉git2件事:

1,当你处于master branch, 默认的remote就是origin。

2,当你在master branch上使用git pull时,没有指定remote和branch,那么git就会采用默认的remote(也就是origin)来merge在master branch上所有的改变

如果不想或者不会编辑config文件的话,可以在bush上输入如下命令行:

  1. $ git config branch.master.remote origin
  2. $ git config branch.master.merge refs/heads/master

之后再重新git pull下。最后git push你的代码吧

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:git的使用 出自老鄢博客 | 欢迎分享