Git For Windows

来源:互联网 发布:黑米抢购软件靠谱吗 编辑:程序博客网 时间:2024/06/04 23:11

12.8

1.如果要在Windows下使用Git,可以有两种方式,分别是Cygwin和msysGit。



安装msysGit,下载网址:https://git-for-windows.github.io/







2.设置用户名,邮箱并生成秘钥添加到GitHub网站中。

打开Git Bash,并输入如下命令:
git config --global user.name "用户名"
git config --global user.email "邮箱"
ssh-keygen -t rsa -C "邮箱"

3.GitHub中新建一个库并在Qtcreator设置git

在GitHub网站中新建一个库,并选择添加README.md文件。
在当前本地项目中,右键Git Bash Here,在窗口中输入git init.
下一步,
git remote add origin https://github.com/waldenlakes/Advanced_UCF_shadow_mark.git
git push-u origin master
提示:
$ git push -u origin master
error: src refspec master does not match any.
error: failed to push some refs to 'https://github.com/waldenlakes/Advanced_UCF_shadow_mark.git'

在http://www.jianshu.com/p/8d26730386f3中发现,可能是github的remote上已经有了文件,会出现错误。此时应当先pull一下,即:
git pull origin master
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), done.
From https://github.com/waldenlakes/Advanced_UCF_shadow_mark
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
此命令完成后,发现remote上的README文件被下载到本地目录下,

接着,
$ git push -u origin master
Everything up-to-date
Branch 'master' set up to track remote branch 'master' from 'origin'.
发现,remote上并没有当前工程里的文件。

后开在本地README文件里面写如hello,然后git push origin master
发现,改动并没有上传到remote上。
-----------------------------------------------------------------------------------------------------------
12.9
现在,我把项目clone到本地目录,后来上传就成功了。
一般步骤就是,当你改动文件,或者新建一个文件的时候,先要
执行git add filename,这一步将修改的内容或文件添加到称之为stage的暂存区里面。
接着执行git commit -m "提交信息",将暂存区的内容都提交到当前的分支,
最后执行git push origin master。将网站上的主分支修改。

git remote add origin git@github.com:yourName/yourRepo.git,添加远程地址。
后面的yourName和yourRepo表示你再github的用户名和刚才新建的仓库,加完之后进入.git,打开config,这里会多出一个remote "origin"内容,这就是刚才添加的远程地址,也可以直接修改config来配置远程地址。





git remote rm origin 这个是删除了origin这个远端的仓库和你本地的映射

问题1:


分析:更新被拒绝了,因为远程包含有本地没有的工作。这个通常是另一个仓库push时引起的。在push之前,你可以通过pull先把远程的改变完善。

解决,通过git pull origin master


提示README.md出现冲突,

本地项目内容如下:


remote里的内容如下:



后来就git add README.md,并commit和push

解决问题。


如果想要删除当前工作目录下的文件,

git rm main.txt

git commit -m "del_main.txt"

git push origin master

结果:

删除当前目录下的main.txt,同时会删除remote下的文件。


问题2:

2.1现在remote下的工程,A和B都同时clone到本地,然后,做了修改,比如A对a文件做了修改,B也对a文件做了修改也添加了b文件,如果B先提交了,那么remote是B的状态,然后此时A做提交时,B的状态已与CLONE时的状态发生了变化,此时怎么办?

2.2如果自己先在本地完成了项目,现在想放到github上面,应该怎么做?

首先要先在remote上创建一个新的仓库,不要添加README.md文件。

第二步,在本地目录下右键打开git BASH,打开窗口,然后在窗口中输入git init,使之变成git。

第三步,连接remote上,执行git remote add origin git@github.com:yourName/yourRepo.git

第四步,git add ,git commit -m,git push origin master。添加所有的文件,然后push。

此时目录下如果有个二级目录怎么办?

git add ./test/readme.txt

2.3remote上的项目,想放到本地,直接git clone就OK了。

参考网址:

http://www.runoob.com/w3cnote/git-guide.html【Github 简明教程】

https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000/0013745374151782eb658c5a5ca454eaa451661275886c6000【工作区和暂存区】

http://www.worldhello.net/gotgit/01-meet-git/060-install-on-windows-msysgit.html

https://www.alexleo.click/how-to-install-git-on-windows/

http://blog.csdn.net/hebbely/article/details/52495073【Qt Creator 中使用 Git / Github】

http://www.jianshu.com/p/8d26730386f3【github上传时出现error: src refspec master does not match any解决办法】


原创粉丝点击