Posts tagged with “git”

A guide for git status change

状态标识

标志 含义
nul 文件已提交到版本库未做修改
?? untracked 新文件尚未 git add
A staged 已经 git add 但尚未提交
AM staged 未提交又做限新的修改,新修改尚未staged
MM 一些修改staged之后又做了新的修改,新修改尚未staged

状态转换指南

状态A -> 状态B 需要的操作
nul -> M 修改文件
MM -> nul git checkout HEAD file(s) OR git checkout -- file(s)
A -> ?? git rm --cached file(s)
M -> M git add file(s)
A -> AM git reset file(s)
A -> nul git reset file(s)
?? -> A git add file(s)
A -> ?? git rm --cached file(s)
A -> AM git add 之后再修改文件
AM -> A git checkout -- file(s)

`git rm --cached ` is a worse choice than `git update-index --assume-unchanged `

There are 3 options, you probably want #3

  1. This will keep the local file for you, but will delete it for anyone else when they pull.

    git rm cached or git rm -r cached

  2. This is for optimization, like a folder with a large number of files, e.g. SDKs that probably won't ever change. It tells git to stop checking that huge folder every time for changes, locally, since it won't have any. The assume-unchanged index will be reset and file(s) overwritten if there are upstream changes to the file/folder (when you pull).

    git update-index --assume-unchanged

  3. This is to tell git you want your own independent version of the file or folder. For instance, you don't want to overwrite (or delete) production/staging config files.

    git update-index --skip-worktree

It's important to know that git update-index will not propagate with git, and each user will have to run it independently.