Git command
Last updated
Last updated
If you modify file, and commit it. Now you want to delete the file on Git and working directory, usegit rm <file>
to remove file from working directory and stage, then git commit
.The removing action would be recorded as a new commit.
If you commit new files, and want to remove them all, just to find the commit that doesn't contain these files. Use the following code:
The first line of code get reset...
repoint HEAD to the commit mentioned, copy file to stage, and refresh working directory according to it. The action would cause "your branch behind origin/ master", so you can't just git push
to remote repository, must use git push --force
.
You could use the code to cancel the uncommitted modification: git checkout -- <file>
. It copy the file on stage to cover working directory. git checkout -- .
With a dot, it cancel all the uncommitted modification.
If you add file to stage mistakenly, use code git reset HEAD <file>
to unstage. It would copy the file on commit and thus cover the file on stage.
Creating repo:
Clone repo:
local:
remote:
Working Procedure of Local repo: working directory-add
-index(stage)-commit
-HEAD
Add file:
Commit:
Push to remote:
若还没有克隆现有仓库,并欲将你的仓库连接到某个远程服务器:
Creat "feature_x" branch, and switch to it:
Switch back to another branch(e.g. master):
Delete feature_x branch:
You need to push the branch to remote, unless it's unseen:
Refresh local repo to the newest :
Fetch and merge remote modification:
Sometime, the merge could come cross conflicts, then you need to modify file manually, when you complete, add the file:
To find the difference between different version:
Tag: git tag 1.0.0 1b2e1d63ff
( 1b2e1d63ff is the ID of file which you can get through git log
)
Cancel local modification to the file in Head:
If you want to discard all your local modification and commits, you can get the version in remote repo, and aim your local brach to it:
GUI: