IDE将本地项目创建git仓库
VCS--create git repository--指定当前项目的目录
查看当前git仓库文件状态
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git status # 查看当前git状态
fatal: not a git repository (or any of the parent directories): .git
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.idea/
httptest/
main.py
tools/
nothing added to commit but untracked files present (use "git add" to track)
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git add . # 添加当前目录下所有文件到版本库暂存区
warning: LF will be replaced by CRLF in .idea/inspectionProfiles/profiles_settings.xml.
The file will have its original line endings in your working directory
这里出现一个warning: LF will be replaced by CRLF in **的警告
原因:LF和CRLF其实都是换行符,但是不同的是,LF是linux和Unix系统的换行符,CRLF是window 系统的换行符。这就给跨平台的协作的项目带来了问题,保存文件到底是使用哪个标准呢? git为了解决这个问题,提供了一个”换行符自动转换“的功能,并且这个功能是默认处于”自动模式“即开启状态的。
这个换行符自动转换会把自动把你代码里 与你当前操作系统不相同的换行的方式 转换成当前系统的换行方式(即LF和CRLF 之间的转换),这样一来,当你提交代码的时候,即使你没有修改过某个文件,也被git认为你修改过了,从而提示"LF will be replaced by CRLF in *****"
解决
最简单的一种办法就是把自动转换功能关掉即可。
输入命令 :git config core.autocrlf false (仅对当前git仓库有效)
git config --global core.autocrlf false (全局有效,不设置推荐全局)
然后重新提交代码即可
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git commit -m '第一次提交' # 提交到版本库,并填写版本说明,以便以后回滚。
[master (root-commit) 477d07e] 第一次提交
20 files changed, 623 insertions(+)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/pythonProject1.iml
create mode 100644 .idea/vcs.xml
create mode 100644 httptest/__init__.py
create mode 100644 httptest/__pycache__/__init__.cpython-37.pyc
create mode 100644 httptest/__pycache__/host.cpython-37.pyc
create mode 100644 httptest/host.py
create mode 100644 httptest/request_demo.py
create mode 100644 main.py
create mode 100644 tools/__init__.py
create mode 100644 tools/__pycache__/__init__.cpython-37.pyc
create mode 100644 tools/__pycache__/mysq_config.cpython-37.pyc
create mode 100644 tools/count_time.py
create mode 100644 tools/data_field.py
create mode 100644 tools/mysq_config.py
create mode 100644 tools/role_clean.py
create mode 100644 tools/training_summary.py
通过git log 查看版本记录
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git log
commit fa506b906bee12caa7c4c87967222bbc38b6d28c (HEAD -> master)
Author: shenzhenghuan <shenzhenghuan@styd.cn>
Date: Mon Jan 9 14:52:53 2023 +0800
清洗角色脚本修改
commit 477d07e291fdce8510c8685c848a34601cec8d47
Author: shenzhenghuan <shenzhenghuan@styd.cn>
Date: Mon Jan 9 14:47:40 2023 +0800
第一次提交
回滚版本用git log的查看版本提交记录后,使用git reset --hard 记录号
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git reset --hard 477d07e291fdce8510c8685c848a34601cec8d47
HEAD is now at 477d07e 第一次提交
如果想回到回滚前的版本,可以使用git reflog查看后回滚
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git reflog
477d07e (HEAD -> master) HEAD@{0}: reset: moving to 477d07e291fdce8510c8685c848a34601cec8d47
fa506b9 HEAD@{1}: commit: 清洗角色脚本修改
477d07e (HEAD -> master) HEAD@{2}: commit (initial): 第一次提交
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git reset --hard fa506b9
HEAD is now at fa506b9 清洗角色脚本修改
PS C:\Users\EDZ\PycharmProjects\pythonProject1>
项目开发到一半,有临时紧急bug需要修复,一半会切换到新的branch,开发完再回到原先的分支
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git branch #查看当前分支
* master
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git branch dev #新建dev分支
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git checkout dev #切换到dev分支
Switched to branch 'dev'
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git branch #当前已切换到dev分支
* dev
master
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git checkout master #切换回master分支
Switched to branch 'master'
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git merge dev #merge 合并dev分支
Updating fa506b9..29f14c3
Fast-forward
tools/role_clean.py | 2 --
1 file changed, 2 deletions(-)
在github上创建远程仓库,将本地仓库push到远程仓库
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git remote add origin git@github.com:sqxz/pythonPrpject.git #本地项目关联远程仓库
PS C:\Users\EDZ\PycharmProjects\pythonProject1> git push -u origin master #推送本地master分支到远程仓库
Enumerating objects: 35, done.
Counting objects: 100% (35/35), done.
Delta compression using up to 4 threads
Compressing objects: 100% (33/33), done.
Writing objects: 100% (35/35), 11.89 KiB | 640.00 KiB/s, done.
Total 35 (delta 6), reused 0 (delta 0)
remote: Resolving deltas: 100% (6/6), done.
To github.com:sqxz/pythonPrpject.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.