How to delete any commit from commits table in Gitlab? - github

In this image you can see list of commit, I want to delete one of them, but I could not find the delete option.

To revert(the right nomenclature) a commit directly on Gitlab it all you need to do is:
Enter the commit you want to revert by clicking on its name;
Click on the button Options;
Click Revert.
Note that similar to reverting a Merge Request, you can opt to revert the changes directly into the target branch or create a new Merge Request to revert the changes.
You can follow the official documentation for more details: https://docs.gitlab.com/ee/user/project/merge_requests/revert_changes.html#reverting-a-commit

Related

Revert merge in pending changes but keep local changes (Azure Devops)

I just accidentally merged to a branch that I had 40+ local changes on - so now my changes and the merge are together, which I definitely do not want, with a lot of the files having edit & merge changes. I want to completely revert out the merge, is there a way to do this? If not, I'm in trouble.
I haven't checked anything in, I just only want to keep my local changes that I made.
If you merge to a branch via pull request in Azure Devops, then you can revert the completed pull request directly.
In Target branch, select the branch where you want to undo the pull request changes.
In Topic branch name, select a new branch where the reverted changes are created, then select Revert.
Select Create pull request to merge the newly created branch in a second pull request to complete the revert. For details ,please refer to this document.
If I ignore something, you could attach detailed steps or flow for this issue , this would be much easier for me to understand and reply.
I agree with Leo BL. You can try to copy your current project folder into temporary folder. Then checkout the merge source branch and compare it with temporary folder by some diff/merge tool. However, that maybe difficult to cut your changes if they were in the same files with the merge operation.
Just a quick hint: Basically, this is a git question. So maybe you should consider giving it the git tag aswell, so you can reach a greater audience.
Regarding your question: What means local change? Is the stuff not committed at all? What does git status show?
Assuming the changes are not committed, you could use git stash. I recommend this SO question:
Cancel git merge but keep local changes
I would try it this way:
1. Backup the directory (so you have a backup if something goes wrong)
2. Stash your changes
3. Revert the merge
4. Load the stashed changes
—> You should be fine
sorry but you are in trouble. After the merge the files are replaced

Source tree not able to push

So I make my file changes, but when I try to push them source tree complains that some one else pushed before me.The files are different,yet I am forced to merge the changes. Some times I have to backup and reset my workspace before it can allow me to push again
Is there no way to force the push?
Open SourceTree Preferences
Tab: Advanced
Third checkbox: Allow force push
Enable the checkbox and close Preferences.
Next time you push, there will be an extra checkbox: Force push.
Checking it will also display an additional Confirm Force Push dialog box before the force push is actually performed.
Even though the files are different, you have to perform a merge or a rebase before you can push. The commits from your current working branch have to be merged into the current branch that exists on the server before you can update it. You're merging the branches, not the files.
Using the "force push" command does not force your commits to be applied in addition to what is on the remote branch - it forces your commits to replace the commits on the remote branch. Using this option would throw away all of the commits that had been made by the other user.
Because this is a destructive operation, SourceTree does not include GUI access to the "force push" command. Here's what Steve Streeting from Atlassian says about it:
SourceTree doesn't expose force push because it's almost always not what you want to do.
It means that someone else has pushed before you. What you should be doing is pulling their changes, merging them (or rebasing your changes on top of them), and then pushing.

In GitHub, is there a way to see all (recent) commits on all branches?

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

Sourcetree - undo unpushed commits

I am using Sourcetree for Windows for a git-repository and would like to undo an unpushed commit.
Is that possible? If I do "revert commit", it creates a second commit which reverts the first commit, but I don't want the first commit to appear at all in my source control.
I could also delete my local repository and pull it again without my local commit, but maybe there's another way?
Right click on the commit you like to reset to (not the one you like to delete!)
Select "Reset master to this commit"
Select "Soft" reset.
A soft reset will keep your local changes.
Source: https://answers.atlassian.com/questions/153791/how-should-i-remove-push-commit-from-sourcetree
Edit
About git revert: This command creates a new commit which will undo other commits. E.g. if you have a commit which adds a new file, git revert could be used to make a commit which will delete the new file.
About applying a soft reset: Assume you have the commits A to E (A---B---C---D---E) and you like to delete the last commit (E). Then you can do a soft reset to commit D. With a soft reset commit E will be deleted from git but the local changes will be kept. There are more examples in the git reset documentation.
If you select the log entry to which you want to revert to then you can click on "Reset to this commit". Only use this option if you didn't push the reverse commit changes. If you're worried about losing the changes then you can use the soft mode which will leave a set of uncommitted changes (what you just changed). Using the mixed resets the working copy but keeps those changes, and a hard will just get rid of the changes entirely. Here's some screenshots:
If you want to delete a commit you can do it as part of an interactive rebase.
But do it with caution, so you don't end up messing up your repo.
In Sourcetree:
Right click a commit that's older than the one you want to delete, and choose "Rebase children of xxxx interactively...". The one you click will be your "base" and you can make changes to every commit made after that one.
In the new window, select the commit you want gone, and press the "Delete"-button at the bottom, or right click the commit and click "Delete commit".
List item
Click "OK" (or "Cancel" if you want to abort).
Check out this Atlassian blog post for more on interactive rebasing in Sourcetree.
If You are on another branch, You need first "check to this commit" for commit you want to delete, and only then "reset current branch to this commit" choosing previous wright commit, will work.

Gerrit always rebase before submit patchset to avoid a merge commit

I found that when clicking "Submit Patch Set" in the Gerrit web interface, it'll either simply add a commit to that branch, or create a merge commit if another commit was submitted just before.
Example that creates 2 commit: The actual commit and a merge commit:
User submits patchset A depending on commit O
User submits patchset B depending on commit O
Submit Patch Set A
Submit Patch Set B --> Creates merge commit between O -> A and O -> B
There is a "Rebase Change" button which is great but it means that to submit a patch set everyone should always do:
Click Rebase Change
Click Submit Change Set
The only reason I see a merge commit useful is to keep dates of the commits (but I do understand why it is required without a rebase).
Isn't there an automatic rebase or at least a check to avoid generating an undesired merge commit?
Yes. Change the Submit Action for your project(s) to Cherry Pick. This will do roughly the same as rebasing when the submit button is pressed. It will keep the clean history you are looking for with no merge commits when submitting changes.
You can change the default submit type of the project by visiting the project settings page and choosing "Rebase if necessary" instead of "Merge if necessary".
For the complete documentation of Submit Types, see: https://gerrit-review.googlesource.com/Documentation/config-project-config.html#submit-type
The method Gerrit uses to submit a change to a project can be modified
by any project owner through the project console, Projects > List >
my/project. In general, a submitted change is only merged if all its
dependencies are also submitted, with exceptions documented below. The
following submit types are supported:
Inherit
This is the default for new projects, unless overridden by a global defaultSubmitType option.
Inherit the submit type from the parent project. In All-Projects, this is equivalent to Merge If Necessary.
Fast Forward Only
With this method Gerrit does not create merge commits on submitting a change. Merge commits may still be submitted, but they
must be created on the client prior to uploading to Gerrit for review.
To submit a change, the change must be a strict superset of the destination branch. That is, the change must already contain the tip
of the destination branch at submit time.
Merge If Necessary
If the change being submitted is a strict superset of the destination branch, then the branch is fast-forwarded to the change.
If not, then a merge commit is automatically created. This is
identical to the classical git merge behavior, or git merge --ff.
Always Merge
Always produce a merge commit, even if the change is a strict superset of the destination branch. This is identical to the behavior
of git merge --no-ff, and may be useful if the project needs to follow
submits with git log --first-parent.
Cherry Pick
Always cherry pick the patch set, ignoring the parent lineage and instead creating a brand new commit on top of the current branch head.
When cherry picking a change, Gerrit automatically appends onto the end of the commit message a short summary of the change’s
approvals, and a URL link back to the change on the web. The committer
header is also set to the submitter, while the author header retains
the original patch set author.
Note that Gerrit ignores dependencies between changes when using this submit type unless change.submitWholeTopic is enabled and
depending changes share the same topic. So generally submitters must
remember to submit changes in the right order when using this submit
type. If all you want is extra information in the commit message,
consider using the Rebase Always submit strategy.
Rebase If Necessary
If the change being submitted is a strict superset of the destination branch, then the branch is fast-forwarded to the change.
If not, then the change is automatically rebased and then the branch
is fast-forwarded to the change.
When Gerrit tries to do a merge, by default the merge will only succeed if there is no path conflict. A path conflict occurs when the
same file has also been changed on the other side of the merge.
Rebase Always
Basically, the same as Rebase If Necessary, but it creates a new patchset even if fast forward is possible AND like Cherry Pick it
ensures footers such as Change-Id, Reviewed-On, and others are present
in resulting commit that is merged.
Thus, Rebase Always can be considered similar to Cherry Pick, but with the important distinction that Rebase Always does not ignore
dependencies.