I have made multiple code commits in my local repository. How do I see the final summary of those code commits combined before pushing the code to remote repository?
Earlier, I used Tortoise GIT(not available in MAC) where I can select those contiguous commits in show log and then right click->combine to one commit to see all the summary of my code changes before pushing the code to remote repository.
How do I achieve something similar in SourceTree without involving squash or anything which might change my git commit history
If the local commits are continuous commits then you can command+Click the already existing commit and the latest local commit to get the final summary of all those commits between these 2 points.
On windows you can achieve that with both 'CTRL + click' and 'SHIFT + click' on the two commits you want to display all changes between.
Related
I am using git on VS2019
I was wondering if there is a way to remove old commits but always keep the latest code. The reason is that when I work on a big change, I do a lot of commits after checking every small step but at the end it is annoying when I click on view history and need to search an old commit to compare the changes. I would like to remove specific commits but leave the changes. In that way I will see on history only the main milestones of the developing process. There is a way to do that??
It sounds like in these scenarios, you're developing a new feature, in which case you should be using a branch+pull request approach to development. During the pull request, you can do a squash merge. It's not all in the command line, but that might be for the best anyway.
If you're already working within a feature branch, then I like VonC's approach.
It seems that you want the git rebase feature.
If you know how many commits you want to squash together, you can use
git rebase -i HEAD~N
You can also do it in interactive mode:
git rebase --interactive HEAD~N
Be aware that if you merging commits you have already pushed, you may have trouble with your next push.
For more details, see: https://www.internalpointers.com/post/squash-commits-into-one-git
You can follow a workflow similar to "Git better with fixups " from Atul Sharma
For the commits which are incremental improvement for the same step, use git commit --fixup small step, which allows you to "do a lot of commits after checking every small step".
(You can see it in Git Extension in Visual Studio)
But at the end, you can cleanup all those small steps with git rebase --interactive --autosquash <First step commit> (assuming you have not pushed those commits yet)
That way, you end up with a cleaner history.
How do I go back to a previous build? For example going back to the July 30 state?
There are a number of ways to functionally undo a series of commits in Git. But given that the branch in question is published, and likely shared by several people, I would recommend using git revert here. git revert adds new commits on top of your current branch which undo previous commits. These revert commits can be thought of as mirror images of what was done in previous commits. Something like this should work:
git revert 00bfe1b^..a013402
This should add two commits, one to undo the Aug-9 commit and one to undo the Aug-13 commit.
As a side note, you could have also done this:
git reset --hard HEAD~2
This would have completely nuked the two commits on top of Jul-30. However, this involves rewriting the history of the branch, which isn't desirable if other people may already be sharing this branch with you. In this case, just play it safe and use git revert.
To view (browse the file tree) the repository state at a certain commit given at least the first four characters of commit's hash, the following URL schema for GitHub can be used (at the time of writing):
https://github.com/{username}/{repository name}/tree/{hash}
If you want to hard reset your GitHub repository to a specific commit, do a git reset --hard {hash} in your local (stored on your computer) repository then force push it to a remote repository (like GitHub) via git push --force.
Of course, hard resets are dangerous. You can git revert or git reset and stash unstaged changes, and I'm sure there are other ways to achieve similar effects.
In GitHub, is there a way to see all recent commits on all branches. It would be best in reverse chronological order.
Maybe I'm snoopy, but I'd like to be able to see what my developers have been up to recently, at least in terms of commits to the repository on github. So far the closest I've seen is the network graph, which is certainly very useful.
Please note: this is not the right answer, although I hope it continues to be useful. NB it has been made a "Community" answer so I don't receive any points from upvotes
To see all commits for a specific branch (so this does NOT actually answer the original question, which is to see commits across all branches):
Click "Code" (left-most tab) on the main page for the repository. Under those 4 buttons ("master", "Go to file", "Add file", "Code") there is a blue rectangle. At the right end of that is a clock icon and a number. If the viewport of your browser is wide enough it even includes (hurrah) the word "commits". This is a link. Click and ENJOY!!!
NB the URL for this page is like this: https://github.com/myProfile/myRepo/commits/master
This is an old feature of GitHub but not really that intuitive.
Using the GitHub website:
Click a project
Click the 'Insights' tab (moved inside the Meatballs menu)
Click 'Network'
Click on the 'node/circle' for each commit to go to that commit.
Diagram below.
Additionally, you can drag to the left to see all commits throughout time for all forks and branches.
I guess there is no any button which shows you a complete list of commits. If you want to list all commits in a repo, you could browse the following URL:
https://github.com/username/repository/commits
You can view the list of commits by adding the word commits (in plural) at the end of repo URL .
Optionally, you could add some query string to narrow the results in the list. For example:
https://github.com/username/repository/commits?author=johndoe
Update
Thanks to #lii I update this post:
If you want to view all commits in a branch, browse the following URL:
https://github.com/username/repository/commits/branch-name
And you could narrow the list of commits by browsing the following URL:
https://github.com/username/repository/commits/branch-name?author=johndoe
The user interface in GitHub does not currently support a way to see your commits in a branch from the code tab. However, I observed that when I select a branch from the branch selector dropdown, I see the following URL:
// This shows me all commits from all users in the branch called "2.2-stable"
https://github.com/jquery/jquery/commits/2.2-stable
If I click on a username in the list of commits, I observe the following URL:
//This shows me the list of commits from the user "mgol" in the master branch (default branch)
https://github.com/jquery/jquery/commits?author=mgol
So, I thought to myself, why not try to add the query string ?author=mgol to the URL that showed commits on a specific branch:
Solution:
// Show me the list of commits from the user "mgol" on the branch called "2.2-stable"
https://github.com/jquery/jquery/commits/2.2-stable?author=mgol
Again, the user interface has no button that lets you see this view (to the best of my knowledge) but you can manipulate the query string to filter only what you want to see.
Since the 'Insights'/'Network' solution is only available for public/GitHub Team repositories, I found a method that works for both private and public repositories.
github.com/username/reponame/branches
Next to the currently selected branch dropdown, there is a link to github.com/username/reponame/branches
This gives you a (clickable) list of all branches with their most recent commits, in chronological order, as asked in the question:
Although this method does not show all commits (only the most recent one) across all branches, this does allow you to check which of the (new) branches has been updated most recently, and further your investigation. I use this all the time.
Look here: Github API: Retrieve all commits for all branches for a repo this is the only options.
On website you can see only branch specific commits - you need to manually switch between them.
Bitbucket allows to see all commits on all branches.
If viewing this from github.com is not a hard requirement, you can use git:
Clone the project locally, then run the following to show the list of all commits from all branches, sorted by date in descending order:
git log --oneline --all --since="Jan 20 2022"
where --since (and --until) allows you to specify a time range and --all displays commits from every branch including remotes. Alternatively you can replace --all with --branches=*.
You can also display the date and authors with something like this:
git log --oneline --pretty="%C(yellow)%h %C(cyan)%cd %C(magenta)%aN%C(auto)%d %Creset%s" --date-order --date=format:"%y%m%d-%H%M" --all --since="Jan 20 2022"
You can also add --graph switch to get a more structured view instead of a plain list.
Please note: dates may not be reliable to track work: some operations will modify history, e.g. a rebase may update the date of old commits to the date of the rebase, squash may keep the oldest date only, a commit date may be modified arbitrarily, etc.
There is no way to attain that within the original GitHub. But there is a work around.
You could use Le Git Graph (read as legit graph), a browser extension that does exactly this.
Install the extension from here : https://chrome.google.com/webstore/detail/le-git-graph-commits-grap/joggkdfebigddmaagckekihhfncdobff
It will add a new "commits" section to every GitHub repo you open. Open the commits graph and there, all commits across branches will be listed along with the git graph.
Hope it helps!
An upvote would be highly appreciated!
The actions tab has all recent activities done on a repo for all branches.
The way I have my repos setup, each developer has a user.git account. I recommend doing the following:
git fetch --all
This fetch updates all the local copies of remote branches but doesn't create new local branches of these tracking remote branches. If you have local branches of all your developer's branches, you will want to run:
git pull --all
So what you need to do is git fetch --all and then git pull --all. I hope this helps.
Lastly, you can also do git remote update which is the same as git fetch --all
best way to access all commit of a repository is
install app of the GitHub on your PCs
clone repo with that
on the history tab you can find all commit
but you need patient and scroll down on this tab ;)
have a good time
Simply run the following command and keep on pressing enter as you see the details of each commit step by step
git log
When reviewing code in eclipse using EGit plugin, before merging it to the develop branch, you switch to the branch and see what files changed with the commits on that branch. For this I would like to see -only- the commits to the current checked out branch. When using Team -> Show in History, I get the complete history across all branches.
How can I view only the commits to the current checked out branch, instead of having to search trough the complete GIT history to find the relevant commits?
Using review tools like Gerrit are not an option.
You can check the filter button in the History View:
All Branches
This toggle activates the "All Branches" mode.
By default, only those commits are shown in the commit log that can be reached from the currently checked out commit, i.e. the Commit Graph ends with the currently checked out commit and newer commits are not shown.
If this button is down, all commits will be shown in the commit log.
This is illustrated in the following picture from our example. The branch "beforeSplit" is currently checked out; by activating the toggle, the newer branches will become visible:
And you need to combine that with:
"Additional Refs" toggles the visibility of certain Refs created during actions like fetch, rebase, merge, for example FETCH_HEAD, ORIGIN_HEAD... This can be helpful to remove clutter from the history view.
You might need to un-check the "Additional Ref" option. please see the attached image.
I know how to rebase onto a specific branch or tag using eGit in Eclipse, but I haven't found a way to rebase onto a specific sha1 using eGit. I'd like to do this in order to squash commits before pushing to upstream (ie, doing git rebase -i HEAD~n where n is some number of commits ago where I want to rebase). Is this possible with eGit? If not, is there another Eclipse plugin I should be using that would provide this functionality?
EGit has rebase, but it does not yet have the interactive rebase you ask for.
I've been successful squashing commits using steps from this post (cut and pasted here):
If I want to squash the last m commits on the current branch then I
select in history the first commit which I don't want to squash
right-click and say "Team->Reset->Soft"
right-click and say "Commit". This commit will contain all the changes of the last m commits together
It is currently available in Eclipse Oxygen, it has it's own wizard for it.
Get the branch you want in the History view
Right-click the commit before the one you want to change
Find Rebase interactive and click it
The Rebase wizard will show up with the commits available to work upon
It works just like the console version, but on a GUI. Even if conflicts arise, it will help you through.
From the history view select the commit you want to rebase to, and create a branch called rebase-point or whatever. Voila, you can now rebase to that branch, and delete it later if you want. I generally prefer using a named branch for things like this anyway, because it minimizes the chance for mistakes on my part. Alternately, consider that origin/master is often the right rebase point if you're squashing commits for a push.
You can also rebase from the Eclipse History view.
Select the repository from the Git Repositories view
Right-click and select Show In History
Select the commit you want to rebase the currently checked out branch on top of
Right-click and select the Rebase on Top of item
Note: You may need to select Show All Branches and Tags first from the History view toolbar to display the commit you are looking for in the table.