Tag Archives: gitlab

How to cancel the commit, how to cancel the commit after git commit, and how to change the submitted content

How does Git cancel commit, how do You cancel the commit after Git commit, and how do you change the commit content
When you’re using Git, you might accidentally click commit, so how do you plug in the commit?
1. You can first check the historical commit record with Git Reflog
Soft, soft
The local code does not change, except that git transitions revert to the pre-COMMIT state
Do not delete the workspace change code, undo commit, and do not undo Git Add.

git reset --soft HEAD~1

Represents the last commit to be revoked, and 1 can be replaced with an earlier number
Hard to cancel
The native code will change directly to the specified commit version. Use with caution
Delete the workspace change code, undo commit, undo Git Add.
Note that after this operation, the last COMMIT state is restored.

git reset --hard HEAD~1

If the message content is just COMMIT, the error is filled in
The input

git commit --amend

Enter ViM mode and make changes to Message
There’s another one, mixed

git reset --mixed HEAD~1

Do not delete the workspace change code, undo commit, and undo git Add. Operation
is the default parameter,git reset –mixed HEAD~1 and git reset HEAD~1 have the same effect.

Giterror: error cloning remote repo ‘origin’ hudson.plugins.git .GitException

Last night the west wind withered green trees, alone on the tall buildings, look to the horizon road
Jenkins + GitLab continuous integration encountered the following error:

ERROR: Error cloning remote repo 'origin'
hudson.plugins.git.GitException: Could not init /root/.jenkins/workspace/eureka-service
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:787)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$2.execute(CliGitAPIImpl.java:579)
	at hudson.plugins.git.GitSCM.retrieveChanges(GitSCM.java:1146)
	at hudson.plugins.git.GitSCM.checkout(GitSCM.java:1186)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep.checkout(SCMStep.java:120)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:90)
	at org.jenkinsci.plugins.workflow.steps.scm.SCMStep$StepExecutionImpl.run(SCMStep.java:77)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:50)
	at hudson.security.ACL.impersonate(ACL.java:290)
	at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:47)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)
Caused by: hudson.plugins.git.GitException: Error performing command: git init /root/.jenkins/workspace/eureka-service
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2023)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1984)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:1980)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:1612)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl$5.execute(CliGitAPIImpl.java:785)
	... 14 more
Caused by: java.io.IOException: Cannot run program "git" (in directory "/root/.jenkins/workspace/eureka-service"): error=2, 没有那个文件或目录
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
	at hudson.Proc$LocalProc.<init>(Proc.java:249)
	at hudson.Proc$LocalProc.<init>(Proc.java:218)
	at hudson.Launcher$LocalLauncher.launch(Launcher.java:935)
	at hudson.Launcher$ProcStarter.start(Launcher.java:454)
	at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2012)
	... 18 more
Caused by: java.io.IOException: error=2, no such file
	at java.lang.UNIXProcess.forkAndExec(Native Method)
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
	at java.lang.ProcessImpl.start(ProcessImpl.java:134)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
	... 23 more

Solutions:
To install Git on Jenkins’ host, execute the following command:
yum install git
Testing:

Gitlab service migration and gitlab administrator password retrieval

service migration

1. Backup the original server data

gitlab-rake gitlab:backup:create RAILS_ENV=production

2. The backups, which are generally located in /var/opt/gitlab/, automatically generate filenames such as 1595350598_2020_07_22_10.0.0_gitlab_backup.tar

Note : due to Gitlab’s own compatibility issues, the higher version of Gitlab cannot recover the data backed up by the lower version. Note that you need to deploy the same version of Gitlab

on server b as on server a
3. After backups, copy the tar file that was just generated to the corresponding directory on the new server:

4. Restore data on new server

gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1595350598_2020_07_22_10.0.0

BACKUP time point must be consistent with the original server BACKUP after the file name

administrator password forced retrieval

1. Connect to the server installed by gitlab via xshell

2. Enter the gitlab-rails console production into the gitlab console. Only after entering the console can you enter the gitlab query statement and it will be parsed

gitlab-rails console production

3. Enter user = user.where (id:1). First query the user object with id 1, because the default for super admin users is 1

user = User.where(id:1).first

4. Enter user.password= ‘password’ and fill in your new password position to

user.password='密码'

5. Then enter user.save! Save the user object

user.save

Log in to the login page to test

Python exports the gitlab project

Python export gitlab project

  1. install python-gitlab module
    pip install python-gitlab
    python3 
    pip3 install python-gitlab
    
  2. gitlab application API access token
    path User Settings -> Access Tokens
  3. configure pythongitlab.cfg and place

    in the same directory

    [global]
     default = username
     ssh_verify = False
     timeout = 8
    
     [username]
     url = https://gitlab.com
     private_token = xxxxxxxxxxxx
    

     

    对于API v4使用url https://gitlab.com,如果您使用API v3使用url
    https://gitlab.example.com

    </引用>

      <>

 

import gitlab
gl = gitlab.Gitlab.from_config('username', ['python-gitlab.cfg'])
projects = gl.projects.list()
print(projects)
  • or use the following code to get the group project
    import gitlab
    class GitlabAPI(object):
    	
        def __init__(self, *args, **kwargs):
            self.gl = gitlab.Gitlab('https://gitlab.com', private_token='xxxxxxxxxxxxx', api_version='4')
    
        # 可行 先获取所有group ID, 然后根据group ID 获取项目地址
        def get_all_group(self):
            return self.gl.groups.list(all=True)
        def get_group_by_id(self, groupID):
            group = self.gl.groups.get(groupID)
            projects = group.projects.list(all=True)
            result_list = []
            for project in projects:
                result_list.append(project.http_url_to_repo)
            return result_list
    
    	
    apiObject = GitlabAPI()
    groupProjects = apiObject.get_group_by_id(填写获取到的groupID)
    print(groupProjects)