Checkout out different version on your snapshot is don’t using the git log –oneline , example if there are many commit for different files , simple check the hash code for each commit using git log –oneline and then checkout the exact version you want . Example git checkout 823kw23 Messenger.Java , then check your editor or IDE NOTE : Nearly everything about the Git is to have a safe history of project
When you want to undo an entire commit from your commit history (telling git to keep a safe version of your project ) use git revert <Commit>
Example : One of your team make a commit and leads to bug , fixing that will be to remove the commit and not to remove the file, using git revert<commit>
Difference between Git revert and Git reset .
- Revert doesn’t change the project history
- Git revert can be use for an individual commit
reset allow you to work with backward commit which may lead to initial point of the project.
- Git reset makes you start your project from scratch and undo local changes
Git revert undo public commit
Suppose you have five files in a single directory which you have all stages using git add . , now you want to make commit to three of the files not all the five files , you only have to make git reset on each file and then make your final commit on the left file , example
git reset FILE A
git reset FILE B
git reset File D
git commit –m’Making commit to File C and E only ’
then use git add fileA – FILEB , FILED
git commit –m’Re staged file A , B AND D’
Now suppose you get your git directory status ( git status ) and you see some untracked files , now you want to remove all untracked files , simply use , now imagine you want to know the file you want to remove , use git clean –n.
Git clean –f will remove untraced file from the current directory
Git clean –df will remove untracked directory and untracked file
Git clean –xf will remove untracked file from in the current directory and all file your git ignores
Git rebase ( Moving a branch of a new base commit ) which helps in rewriting your project histoy i.e maintain a linear project history
One of the major difference between merging and rebasing is merging
- Merge is when you Join two or more development histories together
- rebase is when you Reapply commits on top of another base tip
- Git init Create an empty Git repository or reinitialize an existing one
- Merging result in a three way merge and a single commit
- Rebasing result in a fast forward and linear history commit task
Example : You just hire a new developer , you first him to create a branch on the project file
Assuming he created brack as thus , git brach newDeveloperA, then he need to checkout his new bracnch ( Note all other file in the initial directory remain the same , while he coan continue working on his own file ). Possibly , after he make all his commit using git commit –m’All task is done’, you as the project manager need to checkout each developer branch , assuming you don’t knowing their branch naming, use git branch ( it will show each developer branch ), from there you may check their log and see their commit , if you are okay with developer , you then merge .
- Rebase moves the entire feature branch to begin on the tip of the master branch
- Pulling in upstream changes with git merge results in a superfluous merge commit every time you want to see how the project has progressed
- NOTE : Never rebase commits that have been pushed to a public repository
- Fast Forward Merge all Git has to do to integrate the histories is move (i.e., “fast forward”) the current branch tip up to the target branch tip.
- 3-way merges use a dedicated commit to tie together the two histories.
Git reflog is a mechanism that keep update of each branch
git remote command lets you create, view, and delete connections to other repositories
git Fetching is what you do when you want to see what everybody else has been working on.
Git push make changes available to the project maintainer
git branch -D <branch> to delete a branch
git branch -m <branch> to rename a branch