标签归档:git

git add -A 和 git add . 的区别

Ps:原文时间 2016-09-10 13:30

实践

git add -Agit add .git add -u在功能上看似很相近,但还是存在一点差别

  • git add .:他会监控工作区的状态树,使用它会把工作时的所有变化提交到暂存区,包括文件内容修改(modified)以及新文件(new),但不包括被删除的文件。
  • git add -u:他仅监控已经被add的文件(即tracked file),他会将被修改的文件提交到暂存区。add -u 不会提交新文件(untracked file)。(git add --update的缩写)
  • git add -A:是上面两个功能的合集(git add --all的缩写)

下面是具体操作例子,方便更好的理解(Git version 1.x):

git init
echo Change me > change-me
echo Delete me > delete-me
git add change-me delete-me
git commit -m initial

echo OK >> change-me
rm delete-me
echo Add me > add-me

git status
# Changed but not updated:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git add .
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
# Changed but not updated:
#   deleted:    delete-me

git reset

git add -u
git status

# Changes to be committed:
#   modified:   change-me
#   deleted:    delete-me
# Untracked files:
#   add-me

git reset

git add -A
git status

# Changes to be committed:
#   new file:   add-me
#   modified:   change-me
#   deleted:    delete-me

总结

  • git add -A:提交所有变化
  • git add -u:提交被修改(modified)和被删除(deleted)文件,不包括新文件(new)
  • git add .:提交新文件(new)和被修改(modified)文件,不包括被删除(deleted)文件

git版本不同会有所区别

Git Version 1.x

New Files Modified Files Deleted files Description
git add -A
git add .
git add -u

Git Version 2.x

New Files Modified Files Deleted files Description
git add -A
git add .
git add –ignore-removal
git add -u

转自:https://www.cnblogs.com/skura23/p/5859243.html

macOS 升级后出现xcrun: error: invalid active developer path

Xcode CommandLineTools

发现 macOS 升级系统之后总会报错 git 找不到,无论是 macOS High Sierra ,还是 macOS Mojave

错误信息:

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun

解决方法,重装 xcode CommandLineTools:

xcode-select --install

如果没有解决问题,执行以下命令

sudo xcode-select -switch /

Git-常用命令

develop via a single branch

t branch -m {{branch}}
git fetch origin
git rebase origin/master -i
git push origin {{branch}}

create a new branch

git checkout -b {{branch}}

checkout remote branch

git checkout -b {{branch}} origin/{{branch}}

<!– more –>

merge branch to master

git checkout master
git merge {{branch}}

delete branch

git branch -D {{localBranch}}
git push --delete origin {{remoteBranch}}

rename repo

git remote -v
// View existing remotes
// origin  https://github.com/user/repo.git (fetch)
// origin  https://github.com/user/repo.git (push)

git remote set-url origin https://github.com/user/repo2.git
// Change the 'origin' remote's URL

add tag

git tag {{tag}}
git push --tags

add tag for a history commit

// Set the HEAD to the old commit that we want to tag
git checkout {{leading 7 chars of commit}}

// temporarily set the date to the date of the HEAD commit, and add the tag
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" git tag -a {{tag}} -m "{{commit message}}"

// set HEAD back to whatever you want it to be
git checkout master

git push --tags

delete tag

git tag --delete {{tag}}
git push --delete origin {{tag}}

gh-pages

http://{{group}}.github.io/{{repo}}/

npm add owner

npm owner add {{name}}

一些链接

转自:https://github.com/fool2fish/issues/9