Tuesday 4 December 2018

Git Commands

Git is a version controlling system and to track the files of the application. We can control the changes in files using git commands.

Some of the git commands are as follows:

Git Commands
==============
git reset head (--soft or --hard) // if any errors came while stash
git stash   // to save the data in virtual memory from team explorer
git stash existing-branch other-branch // if you want to move changes from one branch to other branch
git checkout switching-branch-name // if you want to switch to other branch from existing branch
git pull   // to pull the data from TFS
git stash apply    // to get the virtual stashed data to the team explorer
git stash drop    // to drop or clear the virtual stashed data from virtual memory
git stash pop = git stash apply + git stash drop

git config --local --unset credential.helper

if 'fatal: Authentication failed for 'https://some-server.com/tfs/defaultcollection/_git/my-project/': SSL certificate problem: unable to get local issuer certifacate
git config --global http.sslVerify false

git status  //to know the status of the current branch

git status <directory/filename> //to know the status of the file named

git reset head <directory/filename> // to reset exact file name

git checkout  //checkout can be used to other things too, like overwriting your a file in your working copy with a version of that file from another revision

git pull // to pull the fetched files

==========================================================================
steps to pull the data form TFS to master brach when you are in child branch
==========================================================================
git stash
git checkout master
git pull
git checkout my-branch
git stash apply

git merge master
======================================================
if overwritten error occurs then the below steps to follow :
======================================================
git status
git reset head <directory/filename>
git checkout
git pull

=============================================
You cannot publish branch new-branch to remote origin because a branch with the same name already exists in the remote repository. Publishing this branch would result in a non-fast-forward update on the branch in the remote repository.
git reset HEAD~
git stash curren-branch new-branch


=======================================================================
Your local changes to the following files would be overwritten by merge
======================================================================
D:\git\Project1>git merge master
error: Your local changes to the following files would be overwritten by merge:
  Portal/Controllers/ReportController.cs

D:\git\Project1>git stash
Saved working directory and index state WIP on Kodact: ba02491 adding one item

D:\git\Project1>git merge master
Auto-merging Portal/Views/Shared/_AdminTemplate.cshtml
CONFLICT (content): Merge conflict in Portal/Views/Shared/_AdminTemplate.cshtml
Auto-merging Portal/Portal.csproj
CONFLICT (content): Merge conflict in Portal/Portal.csproj Auto-merging Portal/Controllers/ReportController.cs
Automatic merge failed; fix conflicts and then commit the result.

Go to Visual Studio and click on 'all changes' in Team Explorer,

then Confilcted file will show for Merge,

Click on the files and resolve conflicts and commit all merges


====================================================
reset branch as before committed
======================================================
git reset --hard child-branch
git reset --hard HEAD~1

=====================================
revert back the commit based on ID
=====================================
//to get check-in id

git log

//to reset code as commited
git reset --hard HEAD~1

//to revert the code commited based on checkin id
git revert check-inID

============================================
to remove the 'push' at Outgoing Commits
============================================
git reset HEAD^  --hard
       (or)
git reset HEAD^
(or)
git reset HEAD~1
============================================


No comments:

Post a Comment

Note: only a member of this blog may post a comment.