git的使用
同步本地、远程库的分支映射状态
1 | git remote prune origin // origin为远程库名 |
git召回历史版本删除的文件
使用 git 中经常会遇到删除了某些文件,当前没发现问题,知道几个甚至十几个版本后,卧槽,那个文件不该删的。这个时候就要去恢复这个文件了。方法如下
1 | git log // 查看历史版本日志 |
git的一些问题
git clone时报错:
warning: unable to access '/Users/dc/.config/git/attributes': Permission denied
需要给当前用户添加权限1
2
3
4cd ~/
ls -al
<Noticed .config was owned by root, unlike everything else in $HOME>
sudo chown my_user_name .config
git的四种忽略方式
- ~/.gitignore
- .gitignore
- .git/info/exclude
- git update-index –assume-unchanged filepath 参考
git的一些技巧
cherry-pick 拉取其他分支的提交记
Apply the changes introduced by existing commits to the current branch.
To apply changes to another branch, first use git checkout to switch to the desired branch.Apply a commit to the current branch:
git cherry-pick commitApply a range of commits to the current branch (see also git rebase –onto):
git cherry-pick start_commit~..end_commitApply multiple (non-sequential) commits to the current branch:
git cherry-pick commit_1 commit_2Add the changes of a commit to the working directory, without creating a commit:
git cherry-pick -n commit
checkout拉取其他分支的文件或文件夹
- Replace a file in the current directory with the version of it committed in a given branch:
git checkout branch_name – file_name
- Replace a file in the current directory with the version of it committed in a given branch:
git patch 重命名输出文件名称
1 | git format-patch --stdout > [name].patch |
检出没有commit记录的新分支
1 | git checkout --orphan=<new branch name> startPoint |