0
点赞
收藏
分享

微信扫一扫

更新代码

左小米z 2024-05-21 阅读 19

克隆代码

上面的代码编写与提交是我在公司的电脑上完成的,假如我回到了家里想继续编写自己的程序,那么

需要将代码克隆家里的电脑上。

Git

Administrator@XP-201210141900 /d/selenium_use_case/Python_selenium2

$ git clone git://gitcafe.com/fnngj/pyse.git

Cloning into 'pyse'...

remote: Counting objects: 7, done.

remote: Compressing objects: 100% (6/6), done.

remote: Total 7 (delta 1), reused 7 (delta 1)

git://gitcafe.com/fnngj/pyse.git

为提交的项目在 GitCafe 上的地址。通过 git clone 命令就可以把项目克隆到本地。

更新项目

我们克隆文件到本地的目的是进一步地对代码进行修改并提交。

通过 git status 你会发现,我在 pyse 目录下做了比较大的改动,首先修改了

Gitcafehelpdoc.wps 文件,然后新增加了一些文件和文件夹。

提交更新

去克隆一个项目很简单,提交一个项目比较麻烦,必须有相应的权限。因为我已经更换了电脑,所以

我需要再次在本机生成 ssh 公钥,并把生成的公钥添加到 GitCafe 中。具体步骤,参考前面的内容。

测试链接:

Git

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ ssh -T git@gitcafe.com

Hi fnngj! You've successfully authenticated, but GitCafe does not provide shell

access.

提交代码到 GitCafe

Git

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git add . ---添加当前目录下的所文件及文件夹

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git commit -m "add test file and data and report" --对提交的内容进行说明

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git push origin master --提交代码到远程服务器(gitcafe)

fatal: remote error: access denied or repository not exported: /fnngj/pyse.git

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git remote -v

origin git://gitcafe.com/fnngj/pyse.git (fetch)

origin git://gitcafe.com/fnngj/pyse.git (push)

fatal: remote error: access denied or repository not exported: /fnngj/pyse.git

我们在 git push 的时候出问题了,告诉我不能与远程服务器链接。但是通过 git remote -v 查看

你当前项目远程连接的是的仓库地址是 OK 的呀!但是这个 Git 地址只能用于克隆文件到本地,无法通过

这个地址 push 项目。

git@gitcafe.com:fnngj/pyse.git

上面的地址才是一个可以 push 项目的地址。

那么我们就需要把 origin 删除掉,重新以上面的地址建立链接。

Git

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git remote rm origin --删除 origin

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git remote add origin 'git@gitcafe.com:fnngj/pyse.git' --重新链接

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git remote -v -- 现在的链接地址是可以 push

origin git@gitcafe.com:fnngj/pyse.git (fetch)

origin git@gitcafe.com:fnngj/pyse.git (push)

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git push -u origin master --重新 push 项目

Counting objects: 24, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (18/18), done.

Writing objects: 100% (22/22), 45.95 KiB | 0 bytes/s, done.

Total 22 (delta 2), reused 0 (delta 0)

To git@gitcafe.com:fnngj/pyse.git

427652a..efed4f4 master -> master

Branch master set up to track remote branch master from origin.

这一次就可以正常 push 项目了,这也是新手容易迷惑的地方;在 GitCafe 中,克隆项目与提交项目

的地址存在细微的差别,笔者已经在这里踩了坑,希望读者可以避免。

删除提交

通过 Git 管理的项目,有些文件或目录已经废弃掉了,我需要手动删除这些文件或目录,通过 git rm

命令来删除文件。

Git

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git rm baidu.py~ ---删除文件

rm 'baidu.py~'

$ git rm abc/ ---删除目录

rm 'abc'

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git status

On branch master

Your branch is up-to-date with 'origin/master'.

Changes to be committed:

(use "git reset HEAD <file>..." to unstage)

deleted: baidu.py~ ---git 提示删除了 baidu.py~文件

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git commit -m "delete baidu.py~"

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git push origin master

l pull 最新代码到本地

为了避免冲突我们应该形成良好的习惯,在每次 push 代码之先把服务器上最新的代码 pull 到本地。

Git

Administrator@XP-201210.. /d/selenium_use_case/Python_selenium2/pyse (master)

$ git pull origin master

From gitcafe.com:fnngj/pyse

* branch master -> FETCH_HEAD

Already up-to-date.

通过这一节的学习,我们可以自由的随时随地提交自己的代码到 GitCafe 服务器上,在多人开发项目

中,我们会涉及到更多的技术,例如 Git 的分支等。代码版本控制不是本书重点,笔者在这里更多的是起

一抛砖引玉的作用,目前 Git 的相关文档已经相当丰富了,读者可以进一步的学习。


举报

相关推荐

0 条评论