1. Git basic structure
2. Create a project in the git working directory: the following directory
个人信息,没有就创建
git config -l # View personal information
git config --global user.name “xxx” # set personal name global settings
git config --global user.email “xxx” # set personal email
pwd :当前目录
ll 目录下所有文件
git status 查看每个文件状态(红色:该文件没有到本地仓库、暂存区,只是在工作区)
git add a.txt 把文件添加到暂存区
git commit -m "提交了一个a.txt文件" 把暂存区所有文件提交到本地仓库 -m:加批注
git add . 提交所有文件到暂存区
vi user.txt 进入文件内部修改文件内容
git基本命令
git配置
全局设置
git config --global user.name yourname
git config --global user.email youremail
局部设置 争对某个仓库有效
git config --local user.name yourname
git config --local user.email youremail
git init
echo '内容'> 文件名 覆盖
echo '内容'>> 文件名 追加
生成隐藏文件夹.git 代表git仓库
vi readme 编辑一个文件 有则打开编辑,无创建空的文件并打开编辑
按a进入编辑模式,dd:删除一行 ,yy:复制一行 ,p:粘贴
:wq 保存退出 :q 不保存退出 :q! 强制退出
git add 文件名/文件夹 git add . 暂存区
git commit -m '操作的描述'
git reset head 取消add操作 把暂存区的文件撤销
git status 查看git文件状态
git log 查看过去(历史)版本
--oneline 简洁显示
-n行数 查看最新的几行
git reset --hard commit_id 回退到历史版本
git reflog 查看历史版本的将来版本
分支
git branch 分支名
git branch -av 查看分支
git checkout 分支名 切换到分支下
切换到master下操作合并
git merge 分支名 合并分支 有可能遇到冲突
远程仓库
push(推送代码) pull(拉取)
git remote add origin(缺省) 远程仓库地址(ssh https)
git remote -v 查看是否关联远程仓库
git push --all 推送所有
git push origin master
git fetch 远程仓库地址(ssh https) 拉取代码 不会合并
git merge 分支名
git pull 远程仓库地址(ssh https) 拉取代码
gitk --all 查看git的仓库的树信息(工作树)
initialization
git init
If the initialization is successful, the file
flow chart is:
3. Manually modify the file a.txt
At this time, the work area file is modified, then the work area file is different from the local library at this time. If you check the status again, it will report red.
Then we need to add to the temporary storage area and the local library again, (temporary storage Area does not need to be annotated)
4. Example
The graphical interface is as follows:
3.1 Problem: The trunk and branches merge and conflict
Select the content you need to stay, and delete the content automatically generated by git
Delete useless branches
Edit comment
3.2 When an urgent task comes and needs to be temporarily stored, 1. temporarily store 2. then take out
3.3 Ignore files and do not submit: For example, target bytecode files do not submit
If you still want that file not to be submitted, add the condition vi .gitignore to .ignore