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

Git: Revert file after conflict

 Git: Revert file after conflict

Suppose your file got conflicted after taking pull and want to revert changes then use below command.


git checkout HEAD my/filename.js

Reference: 
https://stackoverflow.com/questions/22565184/git-how-to-revert-after-a-merge-conflict-corruption

Git: Get changes from another branch

 Git: Get changes from another branch 


Suppose you are working branchA and somebody merged changes to main branch. You want pull latest changes from main to branchA.

option 1

git checkout main

git pull

git checkout branchA

git merge main


option 2

git rebase main


option 3

git pull origin main



Git: Save user credentials

 Git: Save Username and Password


To avoid prompting username and password, run below command

git config --global credential.helper store

then

git pull


Reference: https://stackoverflow.com/questions/35942754/how-can-i-save-username-and-password-in-git 

GIT: Edit last commit message

 GIT: Edit last commit message (not pushed)


git commit --amend -m "New commit message"

Reference
https://stackoverflow.com/questions/179123/how-to-modify-existing-unpushed-commit-messages

Git: Pulling is not possible because you have unmerged files

 Git: Pulling is not possible because you have unmerged files


Some times I receive this message because local file file changes conflict and requires merging. To revert local changes  in this scenario, use below command

git reset --hard HEAD

If already committed to local branch and need to revert the last committed changes,

git reset --hard HEAD~1

GIT Setup



Steps to setup GIT:

1. Install GIT

2. Go to your code base location

3. Create a .gitigonore file to the root directory of project

4. Add the below content to the .gitignore file
.svn
.gitignore
.DS_Store

5. Run the following command from the root directory. This is to be done only once

git init

6. Run the following commands everytime when you want to commit the changes to GIT

git add --all
git commit  -m "checkin message"

7. Go to backup location where you want to keep the backup files. Execute following command for first time

git clone "$CURRENT_PATH"

eg: git clone C:\wamp\www\app1

8. For updating backup location run the following command

git pull