Skip to content

Latest commit

 

History

History
111 lines (108 loc) · 3.57 KB

man_git.org

File metadata and controls

111 lines (108 loc) · 3.57 KB

git 配置

  1. 用户名和email
    • -global 参数会将这些记录在 ~/.gitconfig 文件,作为默认值
      $ git config --global user.name "Scott Chacon"
      $ git config --global user.email "[email protected]"
              
  2. 配置默认文本编辑器
    $ git config --global core.editor 'emacs'
        
  3. 查看设置值
    $ git config user.name
        
  4. 自己编辑文件内容
    /etc/gitconfig  # 全部用户有效
    ~/.gitconfig   # 当前用户有效
    .git/config   # 当前项目有效
        

git 初始化

  1. 本地初始化
    #项目根目录
    git init
        
  2. 克隆远程库代码
    git clone resp_url
        

提交代码

  1. 添加到本地库
    git add fileName
    git commit -m 'commit content'
        
  2. 提交到远程库
    #origin:远程库名       master:分支名
    git push origin master 
        

将 fork 出来的库与资源库同步

  1. 添加上游仓库
    git remote add upstream resp_url
        
  2. 从上游仓库获取到分支,及相关的提交信息,它们将被保存在本地的 upstream/master 分支
    git fetch upstream
        
  3. 切换到本地分支
    git checkout master
        
  4. 把 upstream/master 分支合并到本地的 master 分支
    git merge upstream/master
        

比较本地库与远程库

  1. 从远程origin仓库的master分支下载到本地并新建一个分支temp
    git pull origin master:temp
        
  2. 比较两个分支的不同
    git diff temp
        

删除本地文件并提交到远程仓库

  1. 删除快照和硬盘中的文件
    git rm fileName
        
  2. 更改提交到本地
    //-m 提交注释
    //-a 自动将在提交前已记录、修改的文件放入缓存区
    git commit -a -m 'remark info'
        
  3. 提交到远程库
    git push origin master
        

clone and checkout

  1. clone is for fetching repositories you don’t have
  2. checkout is for switching between branches in a repository you already have
  3. the answer is coming from: http://stackoverflow.com/questions/7298598/what-is-the-difference-between-git-clone-and-checkout

merge and rebase

https://github.com/geeeeeeeeek/git-recipes/wiki/5.1-%E4%BB%A3%E7%A0%81%E5%90%88%E5%B9%B6%EF%BC%9AMerge%E3%80%81Rebase-%E7%9A%84%E9%80%89%E6%8B%A9

回退文件到指定版本

https://my.oschina.net/u/1186749/blog/668488

怎样删除提交记录但保持文件修改状态

移除某文件夹的版本控制

git rm -r -n --cached "bin/" //-n:加上这个参数,执行命令时,是不会删除任何文件,而是展示此命令要删除的文件列表预览。
git rm -r --cached  "bin/"      //最终执行命令. 
git commit -m" remove bin folder all file out of control"    //提交
git push origin master   //提交到远程服务器

查看文件修改记录

  1. 查看文件提交记录
    git log --pretty=oneline filename
        
  2. 查看某次提交变动详情
    git show commitHash