Showing posts with label Git. Show all posts
Showing posts with label Git. Show all posts

Git how do you revert a commit that has already been pushed and made public

 Remove or fix the bad file in a new commit and then push it to the remote repository. This is the most obvious way to fix an error. Once you have made necessary changes to the file, then commit it to the remote repository using the command: git commit -m “commit message”

Also, you can create a new commit that undoes all changes that were made in the bad commit. To do this use the command

git revert <name of bad commit>

What is Git

 Git is a Distributed Version Control system(DVCS). It lets you track changes made to a file and allows you to revert back to any particular change that you wish.

It is a distributed architecture that provides many advantages over other Version Control Systems (VCS) like SVN. One of the major advantages is that it does not rely on a central server to store all the versions of a project’s files.

Instead, every developer “clones” a copy of a repository I have shown in the diagram with “Local repository” and has the full history of the project available on his hard drive. So when there is a server outage all you need to do to recover is one of your teammate’s local Git repository.

There is a central cloud repository where developers can commit changes and share them with other teammates.

Few Git commands

git rm [file] -  deletes the file from your working directory and stages the deletion.

git log  - list the version history for the current branch.

git show [commit] - shows the metadata and content changes of the specified commit.

git tag [commitID]  - used to give tags to the specified commit.

git checkout [branch name] - used to switch from one branch to another.

git checkout -b [branch name] - creates a new branch and also switches to it.

Create a new branch in Git

 Git makes creating and managing branches very easy. In fact, the power and flexibility of its branching model is one of the biggest advantages of Git!

The "git branch" command is used for a variety of tasks:

creating new local branches

deleting existing local or remote branches

listing local and/or remote branches

listing branches that e.g. haven't been merged yet

create a new branch based on the current HEAD

$ git branch <new-branch>

create a new branch based on some existing one

$ git branch <new-branch> <base-branch>

create a new branch from a specific commit

$ git branch <new-branch> f71ac24d

create a new branch from a specific tag

$ git branch <new-branch> v1.2

create a new branch from a remote branch

$ git branch --track <new-branch> origin/<base-branch>

$ git checkout --track origin/<base-branch>

create a new branch in a remote repository

$ git push -u origin <local-branch>

Write a program in PHP to reverse a number

A number can be written in reverse order. For example 12345 = 54321 <?php   $ num = 23456;   $ revnum = 0;   while ($ num > 1)   {   $...