This content originally appeared on DEV Community and was authored by Danyson
You can classify Git version control mechanism into 8 categories.
- Create
- Track
- Revert
- Update
- Publish
- View
- Branch
- Conflict
Below i have given classification of git mechanism along with their important commands.
Create
When it comes to files
git init
git add .
git add [filename]
When it comes to a repository
git clone ~/folder_A ~/folder_B
git clone git://url
git clone ssh://url
Track
Track is when we want to track our files for commit, update or delete operations.
git add files // adds files ready to be commited
git mv prev_place target_place //moves files
git rm files //removes files from working directory but adds it to the staging index
git rm --cached files //stops tracking but keeps files in working directory
Revert
We use revert when we want to do a new
commit that undoes previous commits.
git reset --hard
The --hard mode is not recoverable so if you want to recover your files after a git reset --hard, follow these steps How to recover our commit after a git reset --hard ?
Other modes of reset ->--soft, --mixed, --merge, --recurse-submodules
git revert branch
git commit -a --amend //replaces previous commit
git checkout <commit_id>
Update
Update is when we want to bring changes to our files.
git fetch //from the original repo that you have forked
git fetch remote
git pull //fetch & merge
git am -3 patch.mbox
git apply patch.diff
Publish
Publish is when we want to establish what we done with our files.
git commit -a //adds all changed files & commits all changes
git format-patch origin //create set of diffs
git push remote //push to origin or remote
git tag //mark current version
View
View is when we want to see the informations about our files.
git status
git diff old_id new_id
git log -p file|dir
git blame file
git show id //meta data & diff
git show id:file
git branch //can list all branches both local and remote
git tag -l //shows list
Branch
The "branch" helps you to create, delete, and list branches.
git checkout branch //switch working dir to branch
git merge branch //merge into current branch
git branch branch_name //branch current
git checkout -b new_branch another_branch //branch new branch from another branch and switch to new branch
Conflict
Conflict arises when two files of same name have different contents so we need to check the difference and maintain our code base without conflicts.
git diff [--base]
git diff --ours
git diff --theirs
git log --merge
gitk --merge
Reference
Personal blog@danyson.github.io
This content originally appeared on DEV Community and was authored by Danyson
Danyson | Sciencx (2021-06-25T22:42:13+00:00) 8 categories of Git. Retrieved from https://www.scien.cx/2021/06/25/8-categories-of-git/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.