How to count the lines changed between two commits in gitlab? - linux

I need to count line changes in the sources in between the particular period of time.
That means, by using the commit Id can I know the line changes count in the source?
I don`t want the line changed per user. I need all the line changes count in between that commits
My gitlab community Edition version is 8.14.3
Update
All my sources exist in the mycompany.gitlab.com. How can I achieve my above doubt?

In your git working directory, run:
git diff <commit-1> <commit-2> --shortstat
You should get an output as following:
7 files changed, 39 insertions(+), 107 deletions(-)

All code referenced can be found in https://docs.gitlab.com/ee/api/commits.html
Get the all the commits (include the since and until parameters):
https://gitlab.example.com/api/v3/projects/:project_id/repository/commits
Response:
Get the differences of a commit
https://gitlab.example.com/api/v3/projects/:project_id/repository/commits/:sha/diff
Split the above endpoints diff field to get the lines changed and sum for each commit.

I found the answer by using below steps
Clone the particular repository to the local machine by using the command git clone https://gitlab.company.com/testgroup/TestProject1.git
Move the source by using the command cd foldername
Use the example command to get the line details git diff --stat

Related

How to fix merge conflicts for a lot of files in git?

I am using the git mergetool command to fix conflicts. However I have thousands of conflicts, is there way to simplify this so I get everything from the remote?
I am asked to enter c, d or a in the command.
{local}: deleted
{remote}: created file
Use (c)reated or (d)eleted file, or (a)bort?
Since I have thousands of files, I don't want to keep sending c. Is there way to just do this in bulk?
You can solve this outside of git mergetool: run git status --porcelain to get a list of all unmerged files and their states in machine-readable format.
If your Git is new enough, it will support --porcelain=v2. See the git status documentation for details on the output formats. Output format v2 is generally superior for all purposes, but you should be able to make do with either one.
Next, you must write a program. Unfortunately Git has no supplied programs for this. Your program can be fairly simple depending on the specific cases you want to solve, and you can use shell scripting (sh or bash) as the programming language, to keep it easy.
Since you're concerned about the cases where git mergetool says:
Use (m)odified or (d)eleted file, or (a)bort?
you are interested in those cases where the file name is missing in the stage 1 ("base") version and also missing in the stage 2 ("local") version, but exists in the stage 3 ("remote") version. (See the git status documentation again and look at examples of your git status --porcelain=v2 output to see how to detect these cases. Two of the three modes will be zero.) For those particular path names, simply run git add on the path name to mark the file as resolved in favor of the created file.
Once you have marked all such files, you can go back to running git mergetool to resolve additional conflicts, if there are any.
Note that your "program" can consist of running:
git status --porcelain=v2 > /tmp/commands.sh
and then editing /tmp/commands.sh to delete all but the lines containing files that you want to git add. Then change all of those lines to read git add <filename> where <filename> is the name of the file. Exit the editor and run sh /tmp/commands.sh to execute all the git add commands. That's your program!
supposing you want their change and modified yours you can do a pull as like:
git pull -X theirs
Other stackOverflow answers
git pull -X
git merge strategies this link will help understand any other merge strategies for the futuro
If you want that all the change you did will be deleted and you will be sync with the remote.
You should do the following:
git stash
git pull
And if you want to restore the change you did you should type:
git stash pop
Basically 'git stash' is moving the change to a temp repository.
you can learn more in:
NDP software:: Git Cheatsheet

Closing a mercurial branch creates a new head?

I'm trying to close an old branch that is no longer used but every time I do the close command on this branch it says a new head is created. Other branches do not have this issue. Does anyone know what my issue could be?
jchan#jchan-Z170N:~/eclipse-workspace/filtec-src/src$ hg --version
Mercurial Distributed SCM (version 3.7.3)
...
jchan#jchan-Z170N:~/eclipse-workspace/filtec-src/src$ hg update -r version1.5.11 -C
1367 files updated, 0 files merged, 6050 files removed, 0 files unresolved
jchan#jchan-Z170N:~/eclipse-workspace/filtec-src/src$ hg commit --close-branch -m "closing legacy branch"
created new head
when i query the list of branches again this branch keeps showing up:
hg branches
...
version1.5.11
Why is this? I am using mercurial command line on Ubuntu 16.04.
Found that I was able to use the tortoise Hg tool "thg" to search and find all the head commits on the miss behaving branch and then merge them all together. After merging all these similar heads together I was able to close the final head and now this branch no longer comes up in the hg branches query.

Is there a way to get all conflicting code snippets (not just files) after a git merge?

Once I execute the git merge A B command, I can get the list of conflicting files using linux command like
git diff --name-only --diff-filter=U
But, is there a way to get conflicting code snippets along with file names? I want to create a report with just the conflicting code snippets.
For example, I need a report like this
src/com/xyz/ABC.java
<<<<<<< Branch_A
this.codeFromA();
=======
this.codeFromB();
>>>>>>> Branch_B
..and the same section repeats for all conflicting files.
Note that there are other lines in the files. But, only the conflicting code piece is returned.
Just run git diff.
Here is explained how it works:
Since Git stages any merge results that are successful, when you run git diff while in a conflicted merge state, you only get what is currently still in conflict
If you are using eclipse, you can get this information from Git staging view.

Handling line endings for git

Here is what I messed up so far,
I copied (not cloned) a rails project from windows to linux pc
Then created a new branch and made lots of changes
At last commited twice whole project and pushed it to a remote repository with windows line endings.
Problem: so my problem is that, since I copied the project from windows to linux, when I run git status whole project shows modified. I don't see the changes I made specifically. Since I committed and pushed whole project, I lost history of files change.
What is needed: So I want to remove my last two commit but I want to keep my changes that I made. Then I want to convert the line endings from windows to unix of whole project so that when I run git status I see only the files that I changed, not whole project. And then I want to commit and push to remote.
It would be nice if there is a solution for this mess.
I am not sure if this will be helpful, I am working on a rails project and my IDE is rubymine.
To undo your last two commits run this:
git reset --soft HEAD~2. This will put the files involved in the commits into your working directory.
Run git status and they will show as staged changes (ready for commit).
Edit your files.
Stage and commit your changes. Important: Don't push
Run git pull.
Run git push
Make sure you commit your changes and do a git pull prior to git push, otherwise your attempt to push will cause conflict and will be rejected.
You can use git filter-branch.
Similar question here.

svn Merge Problem (3 levels of svn)

I am new to use svn and the company in which I work uses three levels (I don't know whether this is a correct word to use here) of svn. I mean the developers are provided a working directory on a testing server. When we commit, it goes to the dev server. When a manager commits it from there it goes to production server. I am a developer here and one of my files is giving error (conflict) when I commit from directory. Not only, but also it gives conflict when manager tries to commit. I am now given access as manager too but I am still unable to resolve it.
What I've tried till now:
svn update
svn delete
svn commit
It gives conflict on all of these operations.
Earlier on a simple error happened and the manager preferred to just delete file on dev, copy it manually and then commit from there. I don't know this may be a reason of this problem or not.
Please help me resolve this issue. I've read some things in read-bean book too but to no avail yet.
Thanks
Ok, here's the update. The actual problem is that a file (ex lib/a.php) used to be in my working directory as well as in dev and production servers. Now it was deleted by someone (using del command, not svn delete) from dev server. Now question here is how I add it again so that it becomes part of svn again. The simple svn add doesn't work.
Update 2
From one of the answers below I understood that its a tree conflict. Some searching brought me to http://svnbook.red-bean.com/nightly/en/svn.tour.treeconflicts.html . Following the instructions, I took the backup of the file and then svn delete it from everywhere. Then I svn add it to my directory, commit it and tried to update dev and production. End result is that it doesn't go there. No error is shown either.
svn info in my directory shows complete info of the file but on dev and production it shows
file_name: (Not a versioned resource)
:S
Any more ideas please?
Alternatively you can take backup of the file ,then say svn revert filename insert you new code.Do a svn up just to make sure you do not have any conflicts,and then commit
Or
fix the conflicts in the file and then you can say svn resolved filename and then you can continue operations on the file
Update:If your file is deleted using rm or del command use svn revert filename to get it back and you do not have to add it again.Just put in your new changes and say svn ci -m"your comments" filename
svn revert will fetch back the last checked in copy into SVN and it wouldnt have your any changes made before the user had used del command
Update 2:After u say svn delete ,u need to commit it until u get the message Deleting filename with a new revision number.Then add the file using svn add command,then commit again.Once this is done you can check the svn info, let me know..
Use svn status command to know the status of the file
The only problem apart from this i can think of is this the directory may not have been added.Is this a new directory?
ah, the old tree conflict problem.
The issue is that SVN is letting you know that you're adding a file that used to be there but it cannot tell whether you're trying to delete it, add it or just update it! So it does the only thing it can - flags a conflict so you can sort it out and fix it. Its basically a conflict on the directory level (rather than a conflict of a file's contents).
What you do is resolve the error (as others have pointed out), then update the directory to get the original file back, then commit your changes. Note that the file was never deleted from SVN - its still in the repo, and if you checkout out a new WC, you'd get the file.
Try to resolve the conflicts then commit again:
svn resolve --accept working

Resources