开始管理仓库
在 GitHub
上新建一个项目(详细参照上一篇 GitHub使用指南
) 在本地创建文件夹以保存项目
cd ~/Desktop
mkdir Git_Projects
将远程项目同步至本地
git clone https://github.com/cooldeepAI/Learning_Notes.git
查看 ~/Desktop/Git_Projects
目录下有 Learning_Notes
工程,可在工程目录下做修改 提交修改至本地仓库
git status
git add new_file
git commit -m "add new_file"
提交修改至远程仓库
git push
or git push origin master
常用操作
撤销 commit (NOT PUSH)
git commit --amend
更改目录/文件名
git mv old_directory[ old_file] new_directory[ old_file]
从远程仓库拉取更新本地仓库
Fetch directly to local and merge remote
在GitHub修改了文件,比如修改文件名,或者修改了文件 将远程仓库拉取至本地仓库
git remote -v
git fetch origin master
比较本地仓库与远程仓库区别
git log -p master.. origin/master
合并本地仓库
git merge origin/master
Fetch indirectly to temp local and merge remote or delete temp
查看远程仓库
git remote -v
拉取仓库,暂存至本地暂存区
git fetch origin master:temp
比较本地仓库和远程仓库
git diff temp
合并/删除 temp
分支至 master
分支
git merge temp
git branch -D temp
其他
在 Terminal
查看使用Git 查看 git status
,中文使用八进制显示,如何解决?
git config --global core.quotepath false
Mac 修改文件后,git status
无显示,如何设置全局忽略 DS_Store
?
添加编辑 home
目录下的 .gitignore_global
文件
vi ~/.gitignore_global
.DS_Store
*/.DS_Store
pwd
修改 home
目录下 gitconfig
文件, 添加全局忽略规则
vi ~/.gitconfig
[ core]
excludesfile = /Users/zxxair/.gitignore_global
若修改中仍有 .DS_Store
文件,可能是已提交至Github,需要删除。
git rm --cached .DS_Store
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
Reference
Git重命名文件和文件夹 Git修改上次提交的Commit 更新远程仓库至本地 Mac git忽略.DS_Store