Skip to content

PrathameshBhagat/Commands

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 

Repository files navigation

Git Commands

git init => Initialise a git repository in the folder
git clone https:// => Clone a repo in new folder
git clone -b <branch> --single-branch https:... => For single branch
git add . => Add all file(s -> .) to staging area to add to next commit
git commit -m " " => Commit/save the code with a message in " "
git commit --amend => Adds change to the previous commit, but it is now a different commit (avoid in remote repos)

Log

git log => Prints all current commits in the current branch
git log --oneline => Prints all current commits in the current branch in oneline
git log --follow -- [file name] => Prints all commits that modified a file
git log -p -u => Prints the difference/commits from the start (git log --all --decorate --oneline --graph)
git status => Check the status of the staging area
git revert <commitID> => Revert a single commit (this works on a remote branch/repo too)

Branch

A branch is just a name associated with a commit(just for understanding)
A commit has a next pointer(just for understanding)
HEAD is just where you currently are, at a particular commit or at a branch's start,
If at a commit, then it is in a "detached state", If at a branch it automatically points to the latest commit of the branch

git branch => Lists branches (if added -a also gives remote branches with local)
git branch [branch name] => Creates a new branch
git branch -d [branch name] => Deletes a branch
git branch -m [old] [new] => Renames a branch
git checkout X.. => To go to a branch or commit (just moves HEAD)
git merge A => Would merge A into the current/existing branch

Merge

If master is just: A
and Branch1 is: A - B => Does not raise conflict issue as no commit needs to be rewritten

If your master is: A - C
and Branch1 is: A - B => Merge raises a conflict issue as C needs to be rewritten

Diff

git diff => Show changes between index(git add ,files only) and working directory
git diff --cached => Between index with last commit
git diff HEAD => Between the files in the working directory and the last commit
(git diff HEAD~3 changes the commit described in the above 2 lines by 3 commits, but the commit should exist)

Reset (Modify local commit history)

git reset --soft <commit ID> => Brings all commits from present to and deletes commit history
But keeps changes in the working directory/folder and staging area
git reset --mixed <commit ID> => Brings all commits from present to and deletes commit history
But keeps changes in the working directory/folder only (same with just git reset as is the default)

Careful Changes below are irreversible !!

git reset --hard <commit ID> =>Deletes the code completely with history and file in working directory
git rebase -i <commit ID> => Reorder/change message/delete/merge commits, etc to commits before
git rebase -i --root => Same as above but rebases all commits from history

A Rebase or a commit automatically aborts if empty message or command

Tags

git tag => Lists all existing tags.
git tag --delete [tag name] => Deletes a local tag

CMD Commands

cls => Clear screen
echo hello> a.php => Write hello in a.php(overrides the complete file)
echo Morning >> a.php => Ammends Morning to hello in a.php
type a.php => Show content in file(del to delete file)
cd .\A => Change directory "A"
cd ..\ => Go one directory/folder back
python -m http.server 8000 => Open web server in one line, folder same as the current directory

Miscellaneous

Tags are the same as branches, they point to a commit, but tags do not change.
Two types of tags : annotated and lightweight
(check below lines once) Annotated:(git tag -a v1.0.0 -m "..." ) just have more information and need to add -a flag (check) Lightweight: just tags and are added as git tag v1.0.0 -m "..."

To convert the OracleVirtualBox OS file(i.e .vdi/.ova ) to a file usable by Windows hyper-v (hypervisor) in CMD
The Format in CMD if you have a virtual box installed is:
start ...vboxmanage.exe clonehd <vdi file> <destination of vhd > --format VDH

Copy complete line and change directories:
start "" "E:\Program Files\Oracle\VirtualBox\vboxmanage.exe" clonehd "E:\Users\DELL\VirtualBox VMs\ubuntu\ubuntu-disk002.vdi" "f:\conv\ubuntuconverted.vhd" --format VHD

Rebase

or a commit automatically aborts if an empty message or command_

  1. First list item
    • First nested list item
      • Second nested list item

This is a quote ghhhh- Markdown - Link

multiple lines in coding for markdown use

p
p