软件工程 第一周的博客

使用Git VCS的一些小技巧

初始化步骤我就大段省略了,大致就是去 Git 官网下载 Binary Dependencies 然后安装就好了,或者是去安装xcode-command-line-tools,其中git自动包含在里面了。

说白了 Git 就是一个 Distributional VCS ,大体就是结合了 Local VCS和Centralized VCS,因此基本步骤就是本地建立一个 Local Repository,再在 Gitea 上建立一个 Remote Repository,然后把两个库连接一下,最后把本地的改动push到 Remote Repository 就可以了。

先说如何建 Local Repository。

选一处“风水宝地”,一般选择/User/home。然后跑到系统默认的 Terminal Emulator 去( Windows:PowerShell ),输入一下指令:

1
2
3
4
5
6
mkdir temp # 建立temp

cd temp # 进入

git init # 初始化 Local Repository

做完最后一步会看到 Git 生成了一个.git的隐藏文件夹。千万不要把自己的项目文件扔进去!

初始化完成后,你就可以开始做项目了。等你做完第一个版本,你就可以把项目addstaging area。用如下指令:

1
git add file.. # add 后可以加入多个文件

然后用git status查看 Local Repository 的状态。如果你看到所有想要staged的文件已经在staging area里面了,就可以上传了。

eg:

1
git commit -m “message"

最后,我们需要创建一个 Remote Repository,过程如下:

1
git remote add origin git@example.git

然后,我们push Local Repo 到 Remote Repository,过程如下:

1
git push origin temp