Daily git
Git commit log
git log --oneline -n 2

where:-
-n 2 :- print last 2 commit only
<code> push origin remote branch </code>
git log --oneline -n 4
where:-
--oneline : to show commit in a single line (otherwise it will print Author,Date etc. details as well as above)
Change/Modify/Amend last commit message
git commit --amend
Above command will pop up a vi/gui editor depends on your configuration. Edit the message and save (vi command -> ESC :wq )
After
Lets take a scenario where you want to merge branch A into branch B but both have some common files e.g. Version/Config.xml with different version or configuration. For example Dev/ReleaseCandiate/Production branches have different version file so while merging our code from Dev to RC/Prod we would not like to update prod Version file with our local Dev version and there are other N number of scenarios.
If you will try to merge branch A into branch B (you always merge branch into current branch) so :-
>>git checkout B
>> git merge A
then git will throw an error message:-
Auto-merging config.xml
CONFLICT (add/add): Merge conflict in config.xml
Automatic merge failed; fix conflicts and then commit the result.
Steps to skip Config.xml while merging:-
1) create a file name .gitattributes at the root level of your git directory.
2) Add an attribute in config.xml in .gitattribute file
Config.xml merge=ours
Version.xml merge=ours
you can define regex or gallop as well like [Config|Version].xml=ours but i need to verify this
where:-
- Version/Config.xml is file that you want to skip while merging
- merge=ours is type of strategies ( ours,their,patient etc)
3) Define a dummy merge strategy
git config --global merge.ours.driver true
Now try to merge A -> B
you have already checked out branch B so
>> git merge A
Merge made by the 'recursive' strategy.
Hence instead of having merge conflicts with Config.xml
git log --oneline -n 2
where:-
-n 2 :- print last 2 commit only
<code> push origin remote branch </code>
git log --oneline -n 4
where:-
--oneline : to show commit in a single line (otherwise it will print Author,Date etc. details as well as above)
Change/Modify/Amend last commit message
git commit --amend
Above command will pop up a vi/gui editor depends on your configuration. Edit the message and save (vi command -> ESC :wq )
After

Merge Branches But Preserve/Skip Few Files
Lets take a scenario where you want to merge branch A into branch B but both have some common files e.g. Version/Config.xml with different version or configuration. For example Dev/ReleaseCandiate/Production branches have different version file so while merging our code from Dev to RC/Prod we would not like to update prod Version file with our local Dev version and there are other N number of scenarios.
If you will try to merge branch A into branch B (you always merge branch into current branch) so :-
>>git checkout B
>> git merge A
then git will throw an error message:-
Auto-merging config.xml
CONFLICT (add/add): Merge conflict in config.xml
Automatic merge failed; fix conflicts and then commit the result.
Steps to skip Config.xml while merging:-
1) create a file name .gitattributes at the root level of your git directory.
2) Add an attribute in config.xml in .gitattribute file
Config.xml merge=ours
Version.xml merge=ours
you can define regex or gallop as well like [Config|Version].xml=ours but i need to verify this
where:-
- Version/Config.xml is file that you want to skip while merging
- merge=ours is type of strategies ( ours,their,patient etc)
3) Define a dummy merge strategy
git config --global merge.ours.driver true
Now try to merge A -> B
you have already checked out branch B so
>> git merge A
Merge made by the 'recursive' strategy.
Hence instead of having merge conflicts with Config.xml
List all the Branches
>> git branch
OR
>> git branch --list
output:-
<branch1>
<branch2>
..............
<branch N>
List all remote Branches
>> git branch -a
Output:-
* master
remotes/origin/HEAD -> origin/master
remotes/origin/change-the-title
remotes/origin/master
remotes/origin/test-branch
Delete a Branch locally
>> git branch -d <branchName>
error: The branch <branchName> is not fully merged.
If you are sure you want to delete it, run 'git branch -D ABC'.
This is a safe operation because git is preventing you from deleting a branch if it has unmerged changes
with -D option git will forcefully delete the branch w/ or w/o branch merge. this is the key difference between (-d) and (-D)
>> git branch -D <branchName>
Deleted branch <branchName> (was xxxxxxx).
Verbose a Branch
>> git branch -v
output will be in 3 columns:-
NameofBranch |SHA1 |commit message
master |32de1e4|first commit message on master branch
>> git branch -vv
with double vv it will print remote branch name mapping along with previous 3 columns
master d0dd1f6 [origin/master] first commit message on master branch
Rename Current Branch
>> git branch -m <new branchName>

Comments
Post a Comment