Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
11 views
in Technique[技术] by (71.8m points)

Concept of git tracking and git staging

When you modify a file in your working directory, git tells you to use "git add" to stage.

When you add a new file to your working directory, git tells you to use "git add" to start tracking.

I am a bit confused about these 2 concepts because i assumed tracking a file for changes is different from staging it for commit

See more detail of this Question&Answers :os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Git essentially has 4 main statuses for the files in your local repo:

  • untracked: The file is new, Git knows nothing about it. If you git add <file>, it becomes:
  • staged: Now Git knows the file (tracked), but also made it part of the next commit batch (called the index). If you git commit, it becomes:
  • unchanged: The file has not changed since its last commit. If you modify it, it becomes:
  • unstaged: Modified but not part of the next commit yet. You can stage it again with git add

As you can see, a git add will track untracked files, and stage any file.

Also: You can untrack an uncommited file with git rm --cached filename and unstage a staged file with git reset HEAD <file>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...