Git basic

个人项目

- clone the repository //this will copy all our team’s files to a local folder on your computer
- make your edits
- git add .    // update all files
- Commit : using -  git commit -a -m “message”
- git push

团队项目 learder

  • git branch dev //create a new branch called dev

  • git checkout dev //point to the new branch dev

  • git checkout master

  • git merge dev //first go to master brach and then merge the dev branch into master

  • git branch -d dev //after merge the dev branch, you can delete it if not used any more

团队项目 member

  • git pull to get the latest update of other members
  • git checkout dev //change the update into dev branch
  • git add -u --update //only add the changed file to repository
  • git add file_1 file_2 file_3 //add file_1, file_2 and file_3

some issue

git stash
git pull
git stash pop

服务器新建代码直接提交

  1. github上新建repo
  2. 已有项目文件夹
git init  # 初始化git项目
git add .
git commit -m "initial"
git remote rm origin
git remote add origin "[email protected]:teletraan/Helmet.git"
git push -u origin master

彻底删除大文件的记录,防止git clone时间太久

  1. 列出所有仓库中的对象(包括SHA值、大小、路径等),并按照大小降序排列,列出TOP 10
git rev-list --all | xargs -rL1 git ls-tree -r --long | sort -uk3 | sort -rnk4 | head -10
  1. 根据最大文件的路径 {filepath},修改此文件的commit历史
git filter-branch --tree-filter "rm -f {filepath}" -- --all
  1. 强制提交到远程分支
git push -f --all

清理git仓库,变成新仓库

1.切换到新的分支

   git checkout --orphan latest_branch

  1. 缓存所有文件(除了.gitignore中声名排除的)
   git add -A

  1. 提交跟踪过的文件(Commit the changes)
   git commit -am "commit message"

  1. 删除master分支(Delete the branch),比较新的项目可能是main,下面的master都换成main
   git branch -D master

5.重命名当前分支为master(Rename the current branch to master)

   git branch -m master

6.提交到远程master分支 (Finally, force update your repository)

   git push -f origin master

gitignore不生效

如果一开始gitignore未考虑周全,导致后续修改了gitignore,也无法再忽略了,此时可以删除对应缓存。个人项目是可以这么做:

git rm -r --cached . 
 git add . 
 git commit -m 'update gitignore'

submodule

如果某一个repo中还包含其他repo的信息,为了保证灵活变更,设置为submodule

你可能感兴趣的:(Git basic)