Git进行代码管理
2013-11-02 11:19
253 查看
在新公司上班一个月了,原来用惯了svn,这回的公司用git,还很不习惯,还好网上资料很多,同时公司也有关于git的书籍,可以拿来看,总算能进行简单的代码管理了。
他的工作流程与svn还是蛮像的:取代码 → 每次工作前更新代码到最新版本 → 修改代码 → 提交代码到服务器
只不过他是用命令行的,当然了git也有可视化的操作工具,但是我没有使用。想使用的可以自己去下载:sourcetree
1. 取代码及修改全局设置
a. 设置用户名与邮箱
b. 从已有的git库中提取代码
2. 每次更改代码的操作
a. 更新本地代码到最新版本(需要merge才能合到本地代码中)
b. 合并更新后的代码到本地
c. 更新代码方式的另一种方法(git pull是git fetch和git merge命令的一个组合)
d. 修改代码后,查看已修改的内容
e. 将新增加文件加入到git中
f. 从Git中删除文件
g. 提交修改
如果想省掉提交之前的 git add 命令,可以直接用
commit和commit -a的区别, commit -a相当于:
第一步:自动地add所有改动的代码,使得所有的开发代码都列于index file中
第二步:自动地删除那些在index file中但不在工作树中的文件
第三步:执行commit命令来提交
h. 提交所有修改到远程服务器,这样,其它团队成员才能更新到这些修改
3. 附注
遇到过的一些错误:
Git – fatal: Unable to create ‘/path/my_project/.git/index.lock’: File exists.
fatal: Unable to create ‘/path/my_proj/.git/index.lock’: File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
可以试着删除 index.lock
他的工作流程与svn还是蛮像的:取代码 → 每次工作前更新代码到最新版本 → 修改代码 → 提交代码到服务器
只不过他是用命令行的,当然了git也有可视化的操作工具,但是我没有使用。想使用的可以自己去下载:sourcetree
1. 取代码及修改全局设置
a. 设置用户名与邮箱
git config --global user.name "My Name" git config --global user.email "my@email.com"
b. 从已有的git库中提取代码
git clone git@server:app .git myrepo
2. 每次更改代码的操作
a. 更新本地代码到最新版本(需要merge才能合到本地代码中)
git fetch
b. 合并更新后的代码到本地
git merge
c. 更新代码方式的另一种方法(git pull是git fetch和git merge命令的一个组合)
git pull
d. 修改代码后,查看已修改的内容
git diff --cached
e. 将新增加文件加入到git中
git add file1 file2 file3
也可以 git add .
f. 从Git中删除文件
git rm file1 git rm -r dir1
g. 提交修改
git commit -m 'this is memo'
如果想省掉提交之前的 git add 命令,可以直接用
git commit -a -m 'this is memo'
commit和commit -a的区别, commit -a相当于:
第一步:自动地add所有改动的代码,使得所有的开发代码都列于index file中
第二步:自动地删除那些在index file中但不在工作树中的文件
第三步:执行commit命令来提交
h. 提交所有修改到远程服务器,这样,其它团队成员才能更新到这些修改
git push
3. 附注
遇到过的一些错误:
Git – fatal: Unable to create ‘/path/my_project/.git/index.lock’: File exists.
fatal: Unable to create ‘/path/my_proj/.git/index.lock’: File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
可以试着删除 index.lock
rm -f ./.git/index.lock
相关文章推荐
- 使用Git进行代码管理心得------------个人练习
- Android Studio 使用git进行代码管理
- mac电脑下将没有做git管理的代码使用github和sourceTree进行代码管理
- Eclipse中只用git上传代码到OSChina进行代码管理
- Git进行代码管理的心得
- 使用Git进行代码管理
- bitbucket和git进行代码管理
- 使用Git进行小项目代码管理
- 使用gitosis和git进行代码权限管理
- 使用GIT进行代码管理的心得
- 开始使用Git工具进行代码管理--记在CSDN空间提交项目的开始
- 使用Git进行代码管理心得
- xcode中进行git代码管理
- 练习一_使用Git进行代码管理的心得
- 使用git进行代码管理
- git创建远程项目并进行代码管理及相关命令
- 使用Git进行小项目代码管理
- bitbucket和git 进行代码管理
- 使用git进行小项目代码管理
- 在VSCode中使用码云(Gitee)进行代码管理