# 执行命令将db.php加入不提交队列
git update-index --assume-unchanged include/db.php
# 执行命令将db.php取消加入不提交队列
git update-index --no-assume-unchanged include/db.php
# 说明:include/db.php 为文件的路径
git status
git add /project/file.txt 添加单个文件
git add /project/ 添加project路径下所有的文件
git reset file 撤销add某个文件
git commit -m "commit message" 本地提交
git push 提交到远程仓库
git pull 从远成仓库下载
git branch 查看分支
git checkout branchname 切换到分支
git checkout -b newBranch 创建分支并且切换到分支
git仓库删除所有提交历史记录,并且上传新版本
1.Checkout
git checkout --orphan latest_branch
2. Add all the files
git add -A
3. Commit the changes
git commit -am "commit message"
4. Delete the branch
git branch -D master
5.Rename the current branch to master
git branch -m master
6.Finally, force update your repository
git push -f origin master、
需求
在一些情况下,我们需要把代码恢复到历史提交的版本。
解决办法
- 找到要恢复的版本的id
- 用 git reset --hard target_version_id 将代码切换到目标 id
- 用 git reset --soft origin/source 命令,将当前代码切换回最新的提交
- 用git commit 提交当前变更
相当于是再最新版本的基础上进行修改,修改成历史的版本。
git 切换远程仓库git remote set-url origin URL
git设置某些文件不加入版本控制
git update-index --assume-unchanged PATH 在PATH处输入要忽略的文件。
git 添加分支
git checkout -b dev #创建并切换到分支dev
重置当前分支的修改内容
git reset --hard HEAD