1.在仓库文件夹中,鼠标右键选择Git Bash Here,然后在界面中输入:
git init 初始化一下仓库(如果之前创建已经初始化可以省略)
2.然后输入:
git add 加要添加的文件或者文件夹
3. git commit -m "这里面是添加文件的备注说明"
4.进行本地与远程仓库相关联
git remote add origin 你需要关联的远程仓库地址
5将远程仓库文件拉到本地
git pull --rebase origin master
6.然后将本地文件上拉到远程仓库
git push -u origin master
这样就完成了本地与远程仓库的操作。
再之后的上传直接可以输入
git push 进行操作。
主要的原因是push上去的时候,仓库内容和本地内容已经不一样了
所以直接拉取最新的下来更改替换即可
通过这条命令:git pull --rebase origin master
然后再git push origin master
远程仓库原来的代码以及分支全被覆盖了,只剩下强制推送上来的代码和master分支的解决办法
# work on local master
git checkout master
# reset to the previous state of origin/master, as recorded by reflog
git reset --hard origin/master@{1}
# finally, push the master branch (and only the master branch) to the server
git push -f origin master
报错:
git pull --rebase origin master
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.
这是因为本地有更改没有提交。
如果需要提交,就git add ,git commit,提交上去;
如果不需要提交更改,就git stash,暂存;
再执行:
git pull --rebase origin master
即可获取更新。
git提交时”warning: LF will be replaced by CRLF“提示
windows平台下使用git add,git deploy 文件时出现“warning: LF will be replaced by CRLF” 的提示。
Git 可以在你提交时自动地把回车(CR)和换行(LF)转换成换行(LF),而在检出代码时把换行(LF)转换成回车(CR)和换行(LF)。 你可以用git config --global core.autocrlf true
来打开此项功能。 如果是在 Windows 系统上,把它设置成 true,这样在检出代码时,换行会被转换成回车和换行:
#提交时转换为LF,检出时转换为CRLF
$ git config --global core.autocrlf true
如果使用以换行(LF)作为行结束符的 Linux 或 Mac,你不需要 Git 在检出文件时进行自动的转换。然而当一个以回车(CR)和换行(LF)作为行结束符的文件不小心被引入时,你肯定想让 Git 修正。 所以,你可以把 core.autocrlf 设置成 input 来告诉 Git 在提交时把回车和换行转换成换行,检出时不转换:(这样在 Windows 上的检出文件中会保留回车和换行,而在 Mac 和 Linux 上,以及版本库中会保留换行。)
#提交时转换为LF,检出时不转换
$ git config --global core.autocrlf input
- git 的 Windows 客户端基本都会默认设置 core.autocrlf=true,设置core.autocrlf=true, 只要保持工作区都是纯 CRLF 文件,编辑器用 CRLF 换行,就不会出现警告了;
- Linux 最好不要设置 core.autocrlf,因为这个配置算是为 Windows 平台定制;
- Windows 上设置 core.autocrlf=false,仓库里也没有配置 .gitattributes,很容易引入 CRLF 或者混合换行符(Mixed Line Endings,一个文件里既有 LF 又有CRLF)到版本库,这样就可能产生各种奇怪的问题。