Tuesday, November 15, 2016

GIT: Updates were rejected because a pushed branch tip is behind its remote

git push -f

The -f makes this a "forced push" and overwrites the branch on the working branch on the server. That would be gone wrong when you are working with other team members. But you can force push when you sure that your local state is correct then it should be fine. You risk losing commit history if that is not the case.

GIT: How to show changed made on files on branch by commit

It will display file changes between two commits (file names only):
git diff OLDER_COMMIT RECENT_COMMIT --name-status

It will display file changes between two commits:
git diff OLDER_COMMIT RECENT_COMMIT

It will display file changes between local changes and specific commit:
git diff COMMIT_NUMBER

Monday, November 14, 2016

Git, see list of latest commits

To see list of commits:
git log

List of commits with file name & status:
git log --name-status

List of previous n commits
git log --name-status -n 2

List of commits by author name:
git log --name-status --author=Pritom (Case sensitive)

List of commits search by file name:
git log --name-status -n 2 --author=pritom | grep "Search"

GIT: How to show the changes on specific commit

Type the following to git bash to show all changes:
git show COMMIT_NUMBER

To show difference between a specific file type:
git show COMMIT_NUMBER file_location/file_name

Type following to show file list changed on the commit:
git show COMMIT_NUMBER --name-status

Will output following:
M       location/file_name (Modified)

A       location/file_name (Added New)

Git list all commits for a specific file

Type to git bash:
git log --follow filename

and to quit from list type:
q

Friday, November 11, 2016

Git - fatal: Unable to create '/path/my_project/.git/index.lock': File exists

Execute the command below:

rm -f ./.git/index.lock

If you have no other git processes running (which is the normal case), go ahead and delete that file.

Untrack files from git using git bash

This will start ignoring the changes to the file:
git update-index --assume-unchanged path/to/file 

When you want to start keeping track again: 
git update-index --no-assume-unchanged path/to/file 

Now list files that are ignored: 
git ls-files -v 

And with a search options: 
git ls-files -v | grep "file_name_part"